-3
A
回答
0
以下代码适用于我!希望会对你有所帮助。
的AndroidManifest.xml
<receiver android:name=".BootCompletedReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<service android:name="NotifyingDailyService" >
</service>
BootCompletedReceiver.class
public class BootCompletedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent arg1) {
// TODO Auto-generated method stub
Log.w("boot_broadcast_poc", "starting service...");
context.startService(new Intent(context, NotifyingDailyService.class));
}
}
硒rvice.class
public class NotifyingDailyService extends Service {
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int onStartCommand(Intent pIntent, int flags, int startId) {
// TODO Auto-generated method stub
Toast.makeText(this, "NotifyingDailyService", Toast.LENGTH_LONG).show();
Log.i("com.example.bootbroadcastpoc","NotifyingDailyService");
return super.onStartCommand(pIntent, flags, startId);
}
}
+0
其工作正常谢谢! – Puri
相关问题
- 1. 打开/关闭Android设备
- 2. 打开系统位置设置后,android对话框不会关闭
- 3. android:检测设置(com.android.settings)是否打开
- 4. 当设备关闭
- 5. 在Chrome中打开或关闭设备仿真模式时进行检测
- 6. 检测设备是否关闭?
- 7. 当设备关闭并再次打开时,闹钟在android中不起作用
- 8. 检测圆括号,打开和关闭
- 9. 检测当我打开一个窗口关闭 - js
- 10. 检测Android设备
- 11. 无法检测到用户在Android设备上的当前位置
- 12. 关闭并重新打开后,如何在后台重新连接BLE设备?
- 13. 检测网站的打开位置从
- 14. 软件设计:数据库打开和关闭的位置
- 15. JavaScript - 打开开关,然后关闭
- 16. 检测移动设备中当前的地理位置
- 17. MFMailComposeViewController打开然后关闭
- 18. Google地图力量关闭GPS位置和半径检测(Android)
- 19. Xamarin Android设置开关位置
- 20. android vibrator打开和关闭
- 21. 打开一个文件(以后将其关闭)仅当标志设置
- 22. 当Android设备处于飞行模式时,打开位置提示失败
- 23. 当设备打开时打开android应用程序
- 24. Android中的闹钟设置关闭和打开
- 25. 如何在位置设置中打开/关闭“使用无线网络”?
- 26. 在关闭时与当已经打开
- 27. 关闭页面的位置元素,然后检索位置()
- 28. 检查设备的当前位置(位置)是否在某个特定位置
- 29. 关闭设备屏幕在android
- 30. 在android中关闭设备的事件
请张贴一些代码,确保您注册的是BroadcastReceiver。 – Phillen
其实我不知道如何检测设备开机状态 – Puri
你的意思是说..你想在Android设备打开时运行广播吗? – Naitik