Android开机启动Service
来源:互联网 发布:linux shell 交互输入 编辑:程序博客网 时间:2024/05/01 21:03
Android4.0以后开机启动service有点麻烦,但照网上的方法实现了,其实是在监听开机广播的时候在BroadcastReciever中启动的service,
启动service的代码为:
public class SysReciever extends BroadcastReceiver{private String TAG = "MySysReciever";@Overridepublic void onReceive(Context context, Intent intent){if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {Log.e(TAG, "开机启动了");Intent startServiceIntent = new Intent(context, SensorService.class);context.startService(startServiceIntent);Toast.makeText(context, "~ Startup Success ~", Toast.LENGTH_LONG).show();} else {Log.e(TAG, "Received unexpected intent " + intent.toString());}}}
AndroidManifest.xml注册方法:
<receiver android:name=".SysReciever" android:enabled="true" android:exported="false" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />记得申明权限。
这样就可以实现在开机的时候启动Service了。
参考:在BroadcastReceiver中启动Service
- Android开机启动Service
- Android开机启动Service
- Android开机启动Service
- 【Android】开机启动 Service
- android开机启动Service
- Android 开机启动Service
- Android activity/service 开机启动
- 【Android】开机自启动Service
- 【Android】开机自启动Service
- 【Android】开机自启动Service .
- Android 开机启动的service
- Android Service 开机自启动
- 【Android】开机自启动Service
- android开机自启动service
- android开机自启动,service
- Android中开机启动service
- android 开机自启动:启动activity、service
- android应用开机自启动&service开机自启动
- cf269d
- eclipse各种常用插件安装
- apache的强劲的消息总线服务
- 使用windows API区分移动硬盘和本地硬盘
- hdu1002——A + B Problem II
- Android开机启动Service
- Qt信号槽机制入门
- yii文章发表之详情页
- 自己的底层代码库(八)——获取函数调用堆栈
- opencv形状分析
- iOS学习之iOS沙盒(sandbox)机制和文件操作
- C#语言static关键字详细解析
- ubuntu安装教程
- windows下使用MinGW+msys编译ffmpeg