我在android应用程序上工作,我只想当我关闭我的设备,当我再次启动我的设备时,我的应用程序应该自我启动,是否有可能android?如果是的话,请帮助,任何帮助将高度appreciated.Thanks。Android设备启动时如何自行启动我的应用程序?
我的自定义广播reciever类:
package com.whizpool.nogademo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class PowerEventReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
我menifast文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.whizpool.nogademo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.whizpool.nogademo.MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustNothing" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.whizpool.nogademo.AEScreenOnOffService" >
<intent-filter>
<action android:name="com.whizpool.nogademo.AEScreenOnOffService" />
</intent-filter>
</service>
<receiver android:name="com.whizpool.nogademo.PowerEventReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
</intent-filter>
</receiver>
<!-- <receiver
android:name=".AutoRestart"
android:enabled="true"
android:exported="true" >
<intent-filter >
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
</intent-filter>
</receiver> -->
<!-- <receiver android:name="com.whizpool.nogademo.MyBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver> -->
</application>
</manifest>
downvote的原因?我尝试提到的链接,但它不工作.. –
@FarhanShah上述链接的解决方案将工作。如果您需要进一步帮助,请发布您的代码 –
这两个链接都适合我。如果这些解决方案都不适合你,你必须比这更具体。不工作的东西可能意味着一千种不同的东西。 –