如何在源代码中禁用/启用android接收器?

如何在源代码中禁用/启用android接收器?,android,receiver,bootcompleted,Android,Receiver,Bootcompleted,我有一个关于安卓接收器的问题。 我可以更改系统应用程序。 当用户打开电源时,B是第一个应用程序。但问题是,当用户选择工厂模式(如设置语言、谷歌id…)时,B应用程序必须启动并完成应用程序设置。这就是为什么要使用android:enabled=“false”和应用程序触发器B应用程序。但不起作用 我认为“android.intent.action.BOOT_COMPLETED”只在启动后发送一次,所以在更改enable receiver B应用程序后,它就不起作用了。是这样吗? 你能给我一些建议吗

我有一个关于安卓接收器的问题。 我可以更改系统应用程序。 当用户打开电源时,B是第一个应用程序。但问题是,当用户选择工厂模式(如设置语言、谷歌id…)时,B应用程序必须启动并完成应用程序设置。这就是为什么要使用android:enabled=“false”和应用程序触发器B应用程序。但不起作用

我认为“android.intent.action.BOOT_COMPLETED”只在启动后发送一次,所以在更改enable receiver B应用程序后,它就不起作用了。是这样吗? 你能给我一些建议吗

应用程序

B App AndoidManifest.xml

<receiver 
    android:name="com.test.myapp.receiver"
    android:enabled="false">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

为什么不直接从应用程序A启动应用程序B?是,启动完成仅触发一次。但是您可以在没有任何接收器的情况下启动应用程序B,

您可以使用默认方法
registerReceiver()
&
取消注册Receiver
。有关更多信息,请参阅:
<receiver 
    android:name="com.test.myapp.receiver"
    android:enabled="false">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>
public void onReceive(Context context, Intent intent) {
    if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
       Intent startMainActivityIntent = new Intent(context, new.class);
       startMainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       context.startActivity(startMainActivityIntent);
}