在小米2A(Android 4.1版)中,除非启动我的应用程序,否则重启后无法接收任何广播。小米默认情况下会禁用应用程序的启动完成广播,除非用户打开它。
我在这里读了很多文章:
Broadcast receiver not working in ICS if the app is not started atleast once
http://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html
Cannot receive broadcast in ICS
他们都说Google只是在Android 3.0之后才实现的。事实是,在Android 4.3的Galaxy Nexus上,即使在重启后未启动应用程序,也可以接收自定义广播(未完成启动)。
即使使用小米系统,在我打开应用程序的启动完成权限后仍可以接收广播。有人可以告诉我为什么吗?
这是发送意图:
Intent intent = new Intent();
intent.setAction("com.test.test");
intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES | intent.getFlags());
context.sendBroadcast(intent);
并且接收如下:
<receiver
android:name="com.test.TestReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.test.test"></action>
</intent-filter>
</receiver>
public class TestReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.test.test")) {
Log.e("Chris", "received test action");
}
}
}
最佳答案
在小米中,您可以选择所有可以自动启动的应用程序。
Security App > Permissions > Autostart
您可以在此处允许您的应用自动启动。
我认为这可以解决您的问题