Java 重新启动后,BroadcastReceiver不工作

Java 重新启动后,BroadcastReceiver不工作,java,android,notifications,broadcastreceiver,alarmmanager,Java,Android,Notifications,Broadcastreceiver,Alarmmanager,我的广播接收器工作正常,但当我重新启动手机时,所有通知都停止工作 AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.a52780.nontifications" android:installLocation="int

我的广播接收器工作正常,但当我重新启动手机时,所有通知都停止工作

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.a52780.nontifications"
    android:installLocation="internalOnly">

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver
            android:name=".AlarmReceiver"
            android:priority="999">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </receiver>

    </application>

</manifest>
<receiver
        android:name="com.example.a52780.nontifications.AlarmReceiver"
        android:enabled="true"
        android:exported="false"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
        </intent-filter>
    </receiver>

    <service
        android:name="com.example.a52780.nontifications.BootService"
        android:enabled="true"
        android:exported="false"/>

我还尝试将android:enabled=“true”和android:exported=“false”放在接收器中。但它不起作用。应用程序安装在手机内存中,而不是SD卡上。BroadcastReceiver应该可以工作,但在重新启动后它就不能工作了

我刚刚找到了解决方案

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.a52780.nontifications"
    android:installLocation="internalOnly">

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver
            android:name=".AlarmReceiver"
            android:priority="999">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </receiver>

    </application>

</manifest>
<receiver
        android:name="com.example.a52780.nontifications.AlarmReceiver"
        android:enabled="true"
        android:exported="false"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
        </intent-filter>
    </receiver>

    <service
        android:name="com.example.a52780.nontifications.BootService"
        android:enabled="true"
        android:exported="false"/>
AlarmReceiver.java

我在MainActivity中更改了调用intent的代码。 旧的:

Idk为什么,但在添加

intent.setAction("android.intent.action.BOOT_COMPLETED");
intent.setAction("android.intent.action.QUICKBOOT_POWERON");

1.在onReceive()中记录任何内容,以确保原因不是通知。2.如果没有显示任何内容,请确保您的应用程序安装在内部存储上,而不是外部存储上storage@Phát Phát,我已经尝试发送通知,如果是intent.getAction()!=null,但它始终为null,即使我不重新启动设备。。
intent.setAction("android.intent.action.BOOT_COMPLETED");
intent.setAction("android.intent.action.QUICKBOOT_POWERON");