2016-10-19 50 views
0

我有这样的应用程序,我想安装它(它是服务),但我没有一个活动,所以我不能在我的设备上安装并试用有人可以帮助我,请我想这是对照片序列livewallpaper像幻灯片,所以任何人都可以告诉我,我该怎么办?应该如何安装这个应用程序?

public class MainActivity extends WallpaperService{ 

Handler handler; 
private boolean visible; 

public void onCreate() 
{ 
    super.onCreate(); 
} 

public void onDestroy() 
{ 
    super.onDestroy(); 
} 

public Engine onCreateEngine() 
{ 
    return new CercleEngine(); 
} 

class CercleEngine extends Engine 
{ 
    public Bitmap image1, image2, image3; 

    CercleEngine() 
    { 
     image1 = BitmapFactory.decodeResource(getResources(), R.drawable.greenww); 
     image2 = BitmapFactory.decodeResource(getResources(), R.drawable.redww); 
     image3 = BitmapFactory.decodeResource(getResources(), R.drawable.screen3); 
    } 

    public void onCreate(SurfaceHolder surfaceHolder) 
    { 
     super.onCreate(surfaceHolder); 
    } 

    public void onOffsetsChanged(float xOffset, float yOffset, float xStep, float yStep, int xPixels, int yPixels) 
    { 
     drawFrame(); 
    } 





    void drawFrame() 
    { 
     final SurfaceHolder holder = getSurfaceHolder(); 

     Canvas c = null; 
     try 
     { 
      c = holder.lockCanvas(); 
      if (c != null) 
      { 
       c.drawBitmap(image1, 0, 0, null); 
       c.drawBitmap(image2, 0, 0, null); 
       c.drawBitmap(image3, 0, 0, null); 
      } 
     } finally 
     { 
      if (c != null) holder.unlockCanvasAndPost(c); 
     } 
     handler.removeCallbacks(drawRunner); 
     if (visible) 
     { 
      handler.postDelayed(drawRunner, 1000); // delay 1 sec 
     } 
    } 
    private final Runnable drawRunner = new Runnable() 
    { 
     @Override 
     public void run() { 
      drawFrame(); 
     } 

    }; 

} 

清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.mike.wallpaper2"> 
<uses-permission android:name="android.permission.SET_WALLPAPER" /> 





     <uses-permission android:name="android.permission.SET_WALLPAPER" /> 





<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 


    <service 
     android:enabled="true" 
     android:name=".MainActivity"> 
     <intent-filter> 
      <action 
       android:name = "me.myapp.MyAppService"> 
      </action> 
     </intent-filter> 
    </service> 
    <receiver android:enabled="true" 
     android:name=".BootUpReceiver"> 
     <intent-filter> <action 
      android:name = "android.intent.action.BOOT_COMPLETED"/> 
     </intent-filter> 
    </receiver> 
</application> 

BootUpReceiver

public class BootUpReceiver extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent intent) { 

    /***** For start Service ****/ 
    Intent myIntent = new Intent(context, MainActivity.class); 
    context.startService(myIntent); 
} 

回答

0

从EditConfiguration 午餐OPTION(无)

0

添加/更新的代码清单中

<service 
    android:enabled="true" 
    android:name=".MainActivity"> 
    <intent-filter> 
     <action 
      android:name = "com.example.mike.wallpaper2.MainActivity"> 
     </action> 
    </intent-filter> 
</service> 
<receiver 
    android:enabled="true" 
    android:name=".BootReceiver"> 
    <intent-filter> 
     <action android:name = "android.intent.action.BOOT_COMPLETED"/> 
    </intent-filter> 
</receiver> 

还增加一个新的类

public class BootReceiver extends BroadcastReceiver { 
@Override 
public void onReceive(Context context, Intent intent) { 
    Intent service = new Intent(context, MainActivity.class); 
    context.startService(service); 
} 
} 

然后按照下面的例子Start android application without activity

提到或重新启动设备此项服务开始运行

+0

我有这个课呢 公共无效的步骤的onReceive(上下文范围内,意图意图){ /*****对于开始服务****/ 意图myIntent =新INTE nt(context,MainActivity.class); context.startService(myIntent); } } – CJS

+0

BootUpReceiver。 – CJS

+0

会议应用:错误共进午餐的活动 – CJS

相关问题