我有这个应用程序我想安装它(它是服务)但我没有活动,所以我无法安装在我的设备上试试它可以有人帮助我,我想这是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 :(得分: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
中提到的步骤操作或重启设备此服务开始运行
答案 1 :(得分:0)
从EditConfiguration 午餐选项(没有)