Android 开机自启动程序的实现
2014-04-21 21:03
543 查看
程序的开机自启动是一个非常有用的特性,在Android中,借助广播接收机制,这种特性非常容易实现,这里以开机启动一个Activity为例说明。Java代码:
/** * @encoding UTF-8 */ package org.flyingcat.os; import org.flyingcat.androidcodelib.MainActivity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; /** * @author Flyingcat * @create 2014-4-21 * @version 1.0 */ public final class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent arg1) { Intent intent = new Intent(context, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } }注:要启动一个Activity,必须添加Intent.FLAG_ACTIVITY_NEW_TASK标志,否则会在执行时抛出异常。AndroidManifest.xml中添加:
<receiver android:name="org.flyingcat.os.BootReceiver"> <intent-filter > <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiver>此外,还需要注册权限:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>如果不注册该项权限,则无法收到BOOT_COMPLETED广播,无法达到开机启动的效果。
相关文章推荐
- qt for android实现程序的开机自启动。
- android实现程序开机自启动
- Android程序开机自启动的实现方式
- Android实现开机自启动某个程序
- Android实现开机自启动某个程序
- Android实现开机自动运行程序
- Android 开机自启动程序
- android 应用程序实现开机自启动
- android开机自启动的后台Service的实现
- Android如何实现开机自启动Service
- Android实现开机自启动无效问题
- 修改注册表 实现开机程序自启动
- VC实现程序开机自启动
- centos下实现程序开机自启动(tomcat为例)
- android实现开机自启动
- Android能否实现一键清理后台程序后程序自启动(类似QQ微信不被清理软件杀死)
- 实现 Android 应用在开机时自启动
- 【转】Android实现开机自动运行程序
- Android实现开机自动运行程序
- Android实现开机自动运行程序