Android开发之设置开机自动启动的几种方法
方法一:
?
1 2 3 4 5 6 7 | <!-- 开机启动 --> < receiver android:name = ".AutoStartReceiver" > < intent-filter > < action android:name = "android.intent.action.BOOT_COMPLETED" /> < category android:name = "android.intent.category.HOME" /> </ intent-filter > </ receiver > |
<!-- 开机启动 --> <receiver android:name=".AutoStartReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <category android:name="android.intent.category.HOME"/> </intent-filter> </receiver>
android:name=".AutoStartReceiver"为处理开机启动后所做操作的AutoStartReceiver.java
方法二:
在4.X版本上测试必须加入该句,测试设备原道N90 8G
?
1 2 | <!-- 开机启动 --> <uses-permission android:name= "android.permission.RECEIVE_BOOT_COMPLETED" /> |
<!-- 开机启动 --> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
方法三:
AutoStartReceiver.Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; /** * 实现开机启动 * @author Owner */ public class AutoStartReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent i = new Intent(context, MainActivity. class ); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } |