Android学习篇章35-Service基础-广播开机启动服务
来源:互联网 发布:mac下载maven 编辑:程序博客网 时间:2024/04/27 19:52
接收开机的广播 BroadcastReceiver:
public class MyBootBroadcastReceiver extends BroadcastReceiver{@Overridepublic void onReceive(Context context, Intent intent) { String action=intent.getAction(); if(action.equals(Intent.ACTION_BOOT_COMPLETED)) { //监听开机启动的广播 //启动服务 Intent service=new Intent(); service.setAction("android.intent.action.Boot_Service"); context.startService(service); }}}
开机启动,开启服务Service:
public class MyBootService extends Service{@Overridepublic IBinder onBind(Intent intent) {return null;}@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {Log.i("test", "开机服务已执行");return super.onStartCommand(intent, flags, startId);}}
manifest.xml:
<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.boot.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name="com.boot.MyBootService"> <intent-filter > <action android:name="android.intent.action.Boot_Service"/> </intent-filter> </service> <receiver android:name="com.boot.MyBootBroadcastReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiver> </application>
- Android学习篇章35-Service基础-广播开机启动服务
- Android学习篇章27-Broadcast广播基础
- Android学习篇章33-Service基础
- Android学习篇章34-Service基础-IntentService
- android 接收开机广播启动service
- android用服务service与广播broadcastreceiver创建开机启动服务
- Android学习篇章28-Broadcast广播基础-BroadcastReceiver
- Android学习篇章31-Broadcast广播基础-短信监听
- Android学习篇章32-Broadcast广播基础-通话监听
- android 广播 android Service 开机启动的Service
- android 广播 android Service 开机启动的Service
- Service 开机接受广播,启动服务的问题
- Service 开机接受广播,启动服务的问题
- Android学习篇章29-Broadcast广播基础-自定义广播(静态广播)
- Android学习篇章30-Broadcast广播基础-自定义广播(动态广播)
- android之手机开机启动Service服务
- android 开机启动服务service的开发
- 开机广播,并启动service
- 浅析Mysql的my.ini文件
- PHP & memcached
- 判断远程文件是否存在的php函数
- java基础2
- 用PHP简易实现中文分词
- Android学习篇章35-Service基础-广播开机启动服务
- Delphi取整函数
- OCP-1Z0-053-V12.02-40题
- java基础3
- 什么是中文分词
- fafu—1174 编辑距离 DP
- JVM调优总结(六)-分代垃圾回收详述2
- Linux下缓存服务器Memcached的应用
- 2. RTX移植