不调用广播 onReceive 方法

Broadcast onReceive method does not get called

由于评论,代码更新了更多具体信息。

Manifest.xml

<receiver
        android:name="com.x.x.x.MyReceiver"
        android:enabled="true"
        android:exported="false">

        <intent-filter>
            <action android:name="com.x.x.x.NOTIFICATION_INTENT_ACTION.TEST" />
        </intent-filter>
</receiver>

MyReceiver.java

internal class MyReceiver: BroadcastReceiver() {

    companion object {
        const val NOT_ID = ".."
        const val NOT = ".."
        const val NOTIFICATION_INTENT_ACTION = "com.x.x.x.NOTIFICATION_INTENT_ACTION.TEST"

    }

    override fun onReceive(context: Context, intent: Intent) {
        // does not get called
    }
}

CreatingIntent.java

    Intent intent = new Intent(this, MyReceiver.class);
    mPendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    mAlarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
    if (mAlarmManager != null) {
        mAlarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 60000L, mPendingIntent);
    }

问题:NotRec class 中的 onReceive 方法没有被调用。我试图将 Manifest 更改为 <receiver android:name="FULL_PATH.receiver.NotRec" /> 但它没有任何改变。有什么想法吗?

移除

android:exported="false"

来自清单中的 <receiver> 声明。

如果您没有 "export" 接收器,则 AlarmManager 无法触发它。当您在清单中将组件标记为 "not exported" 时,这意味着它是 "private" 并且其他应用程序(包括 AlarmManager 等系统应用程序)无法启动或触发该组件。