<span style="font-size:14px;">public class bootReceiver extends BroadcastReceiver {
//要在清单文件中添加这个权限:android.permission.RECEIVE_BOOT_COMPLETED
//同时在清单文件中给receiver添加这个过滤的action
private static final String ACTION = "android.intent.action.BOOT_COMPLETED";
@Override
public void onReceive(Context context, Intent intent) {
if (ACTION.equals(intent.getAction())) {
//在此启动本应用的关键性服务
Intent intnt = new Intent(Intent.ACTION_RUN);
intnt.setClass(context, startService.class);
context.startService(intnt);
}
}
}
//startService中编写具体的逻辑事务,这里就不做赘述了</span>
Android自启动管理
最新推荐文章于 2025-04-24 20:44:29 发布