在配置文件AndroidManifest.xml中向系统注册receiver,子节点 intent-filter 表示接收android.intent.action.BOOT_COMPLETED 消息
<receiver android:name="com.ray.ray.receiver.BootCompletedReceiver" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
同时需要添加相应权限在Receiver中就可以添加开机需要进行的操作
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
在Receiver中就可以添加开机需要进行的操作
public class BootCompletedReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub }
时间: 2024-10-10 01:12:02