BOOT COMPLETE无法在Android(Redmi)中运行

Jig*_*ekh 2 android broadcastreceiver bootcompleted

我目前正在开发一个包含Boot_Completed Broadcast接收器概念的应用程序.我已经在我的摩托罗拉Moto G手机中测试了这款应用.该应用程序运行正常,并显示Toast消息.但是当我在XIAOMI Redmi 1S手机中测试这个应用程序时,它不会显示Toast消息.

我已经看到很多类似于我的问题的问题(如 问题1,问题2等)......但我没有解决这个问题.

我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demoapp"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="internalOnly" >
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.demoapp.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter> 
    </activity>
    <receiver android:name="com.example.demoapp.MyReceiver"
        android:enabled="true"
        android:exported="true" >
        <intent-filter >
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </receiver>
 </application>
 </manifest>
Run Code Online (Sandbox Code Playgroud)

MyReceiver.java

public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    if ("android.intent.action.BOOT_COMPLETED".equalsIgnoreCase(intent.getAction())) {
        Toast.makeText(context, "Boot Complete.", Toast.LENGTH_LONG).show();
    }
}
}
Run Code Online (Sandbox Code Playgroud)

我怎么解决这个问题?

shi*_*vam 7

在XIOMI设备的情况下,您必须手动设置权限,我认为您可以通过在"自动启动管理"列表中添加您的应用程序来解决此问题,该列表可用作默认安全应用程序.

  • 如何将我的应用添加到“自动启动管理”列表中?@用户3188965 (2认同)

Jay*_*yas 5

这是针对您的错误的解决方案。

您需要做的是,您还需要在Intent-Filter中提及此权限。

               <receiver android:name="com.example.demoapp.MyReceiver"
                         android:enabled="true"
                         android:exported="true" >

               <intent-filter >
                       <action android:name="android.intent.action.BOOT_COMPLETED"/>
                       <action android:name="android.intent.action.REBOOT"/>
               </intent-filter>
               </receiver>
Run Code Online (Sandbox Code Playgroud)

在这里,您还需要做一件事。

转到设备中的“设置-应用-打开您的应用信息-管理权限”

在这里检查所有东西。

因为对于某些设备它将无法正常工作。例如Red mi

尝试这个 !