Android 接收不到开机广播,接收不到adb发送的广播

NullPointerK NullPointerK 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
最近在弄一个开机自启动的需求,已经按照一般方法静态注册,写一个接受广播,也将应用安装到系统目录 /system/app,但是就是接收不到广播,也接收不到adb自己发送的广播。哪位大佬能帮帮忙

public class UpdateReceiver extends BroadcastReceiver {
public static final String TAG = UpdateReceiver.class.getSimpleName();

@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
String packageName = intent.getDataString().substring(8);
Log.i(TAG,"BootReceiver onReceive():接收到Intent.getAction() = "+intent.getAction()+" , 包名 = "+intent.getDataString());

/**
* 接收安装广播
* android.intent.action.PACKAGE_ADDED
* */
if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {
Log.i(TAG,"BootReceiver onReceive():安装了:" + packageName + "包名的程序");

}

/**
* 接收卸载广播
* android.intent.action.PACKAGE_REMOVED
* */
if (action.equals(Intent.ACTION_PACKAGE_REMOVED)) {
Log.i(TAG,"接收卸载广播");

}

/**
* 接收更新广播
* android.intent.action.PACKAGE_REPLACED
* */
if(action.equals(Intent.ACTION_PACKAGE_REPLACED)){
Log.i(TAG,"BootReceiver onReceive():更新了:" + packageName + "包名的程序,context.getPackageName()="+context.getPackageName());
Intent intent2 = new Intent(context, SettingActivity.class);
intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);

}
/**
* 接收重启广播
* android.intent.action.PACKAGE_REPLACED
* */
if(action.equals(Intent.ACTION_PACKAGE_RESTARTED)){
Log.i(TAG,"BootReceiver onReceive():重启了:" + packageName + "包名的程序");
Intent intent2 = new Intent(context, SettingActivity.class);
intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);
}

/**
* 接收开机广播
* android.intent.action.BOOT_COMPLETED
* */
if(action.equals(Intent.ACTION_BOOT_COMPLETED)){
Log.i(TAG,"BootReceiver onReceive():仪器开机,开启了:" + packageName + "包名的程序");
Intent intentMainActivity = new Intent(context, SettingActivity.class);
intentMainActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentMainActivity);
}

}
}


<receiver
android:name=".receiver.UpdateReceiver"
android:label="@string/app_name"> <!-- app open/delete/upgrade/completed receiver -->
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" /> <!-- add -->
<action android:name="android.intent.action.PACKAGE_REPLACED" /> <!-- update -->
<action android:name="android.intent.action.PACKAGE_REMOVED" /> <!-- delete -->
<action android:name="android.intent.action.PACKAGE_RESTARTED" /> <!-- restart -->
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
...全文
评论 1
收藏 已收藏
分享
返回顶部
NullPointerK
Android 80,490 成员 91,375 内容