RECEIVE_BOOT_COMPLETED 在 Lollipop 设备中不工作

RECEIVE_BOOT_COMPLETED is not working in Lollipop device

我试图在我的应用程序中实现一个将在启动时工作的接收器。为此,我创建了一个 MyReceiver class,然后将其添加到我的清单中。我也添加了权限。但是它不起作用,也没有显示在应用程序信息中。

这是我的清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.inapp.sampleboot" >

    <uses-permission android:name="ANDROID.PERMISSION.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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=".MyReceiver"
            >
            <intent-filter>
                <action android:name="ANDROID.INTENT.ACTION.BOOT_COMPLETED"/>
                <action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

我的收件人class

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

    }
}

我认为这将是一个解决方案

<uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE" />

Android 在大多数地方区分大小写。请将此更改为:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

您的接收器意图过滤器中有两个操作。那就是问题所在。取而代之的是为接收器设置两个 intent 过滤器。

也许是这样的:

<intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
<intent-filter>
                <action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
</intent-filter>

你真的需要第二个动作吗?

如果您遇到关于此主题的任何其他问题,请仔细阅读:

安装后至少启动一次您的应用程序,然后重新启动您的设备。希望有用