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

时间:2015-01-06 05:32:03

标签: android broadcastreceiver bootcompleted

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

我已经看到很多类似于我的问题的问题(例如 - Question 1Question 2等等)...但我还没有解决这个问题。< / p>

我的宣言:

<?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>

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();
    }
}
}

我该如何解决这个问题?

4 个答案:

答案 0 :(得分:7)

如果是XIAOMI设备,您必须手动设置权限,我认为您可以通过在“自动启动管理”列表中添加您的应用来解决此问题,该列表可用作默认安全应用。

答案 1 :(得分:4)

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

您需要做的是,您还需要在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>

在这里你也需要做一件事。

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

这里检查一切。

因为某些设备不起作用。 Ex.Red mi

试试这个!

答案 2 :(得分:1)

转到管理应用权限

从应用中选择您的应用

切换“自动开始”

完成

答案 3 :(得分:1)

尝试从广播接收器中删除条件

public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Toast.makeText(context, "Boot Complete.", Toast.LENGTH_LONG).show();
}
}