注册开机启动 android,Android-如何设置APP开机启动(图文)

方案:

第一步:接收“开机完成”广播:android.intent.action.BOOT_COMPLETED;

第二步:在广播接收器中启动HelloApp:

AndroidManifest.xml:

package="com.excample.helloapp">

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme">

android:name=".BootCompleteReceiver"

android:enabled="true"

android:exported="true">

广播接收器:

package com.excample.helloapp;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

public class BootCompleteReceiver extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){

Intent thisIntent = new Intent(context, MainActivity.class);

thisIntent.setAction("android.intent.action.MAIN");

thisIntent.addCategory("android.intent.category.LAUNCHER");

thisIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(thisIntent);

}

}

}

------------------------------------------------------------------------------------------------------------------------

图文详解:

首先,你得有一个APP!

创建HelloApp:

1.新建项目,取名HelloApp

118cde55fa31726f3c6107a441757f2e.png

2.下一步(保持默认)

747efabc8f0ed77b432974b508f1d2d6.png

3.下一步(保持默认)

3e97ee23ec3822a26672ea4470114e89.png

4.下一步(保持默认)

b101d0e7865e83dd767ffa8b7be32c62.png

5.修改图示为”Project"(可选)

8f830defd7209f29818571d01c7d3b52.png

6.Project图示效果:

9f85090102bcaeed75ff3813546036f8.png

7.运行

df9a9557b2e2b1ad98da86acb8ec9937.png

8.运行效果:

06005afb27196292930df1fc514213ad.png

设置HelloApp开机启动:

1.

90d2e374c13b53eeb51131ac56a38196.png

2.

614d9380ade788edf1b2918f43146e1a.png

3.在广播接收器中启动HelloApp:

package com.excample.helloapp;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

public class BootCompleteReceiver extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){

Intent thisIntent = new Intent(context, MainActivity.class);

thisIntent.setAction("android.intent.action.MAIN");

thisIntent.addCategory("android.intent.category.LAUNCHER");

thisIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(thisIntent);

}

}

}

4.修改AndroidManifest.xml注册广播过滤器:

package="com.excample.helloapp">

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme">

android:name=".BootCompleteReceiver"

android:enabled="true"

android:exported="true">

5.将编译出来的apk放到/system/app/下面,然后重启

b9ccb5716b010765180420ce26734cd1.png

6.效果

55254ba15cdb7f662f1577e66bd4ff7e.png

Github代码:https://github.com/menghaocheng/HelloApp

(完)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值