首页 > 系统 > Android > 正文

android开机自启动app示例分享

2020-04-11 11:57:36
字体:
来源:转载
供稿:网友

复制代码 代码如下:

/*开机自动启动APP*/
public class BootReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

Log.d("XRGPS", "BootReceiver.onReceive: " + intent.getAction());
if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
           Intent mBootIntent = new Intent(context, MainActivity.class);
           mBootIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           context.startActivity(mBootIntent); 
    } else {
        Log.w("XRGPS", "BootReceiver: unsupported action");
    }
}
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表