【问题标题】:App doesn't show firebase notifications (broadcast intent callback: result=CANCELLED forIntent)应用不显示 Firebase 通知(广播意图回调:result=CANCELLED forIntent)
【发布时间】:2017-06-20 10:48:35
【问题描述】:

当应用被终止或在后台时,我无法收到 Firebase 通知。

我签署了 APK,但它不起作用,当我使用 JSON 发送数据通知时,logcat 向我显示此错误:

   broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.example.paolomazza.firebasedemo3 (has extras) }

鉴于以下清单,此错误的原因可能是什么? 提前致谢

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />

<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">
    <receiver android:name="com.example.paolomazza.firebasedemo3.OnBootBroadcastReceiver">
        <intent-filter >
            <action android:name="android.intent.action.BOOT_COMPLETED" />

            <category android:name="android.intent.category.HOME" />
        </intent-filter>
    </receiver>

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service android:name=".FirebaseIDService">
        <intent-filter>
            <action android:name="com.example.paolomazza.firebasedemo3.INSTANCE_ID_EVENT"
                android:stopWithTask="false" />
        </intent-filter>
    </service>

    <service android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"
                android:stopWithTask="false" />
        </intent-filter>
    </service>
</application>

这是显示通知的代码

public void onMessageReceived(RemoteMessage remoteMessage) {
    Map<String, String> data = remoteMessage.getData();

    //you can get your text message here.
    String text= data.get("my_custom_key");

    System.out.println(text);
    notifies(text);
}

private void notifies(String body){
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(MyFirebaseMessagingService.this)
                    .setSmallIcon(android.R.drawable.ic_menu_help)
                    .setContentTitle("Congratulations!")
                    .setContentText(body);
    Notification mNot= mBuilder.build();
    NotificationManager mNotMan = (NotificationManager)
            getSystemService(Context.NOTIFICATION_SERVICE);
    mNotMan.notify(1,mNot);
}

【问题讨论】:

  • 不,当应用程序在我的 Android 手机中被杀死时,它不会显示通知。我发送了 JSON 数据通知!
  • 您可以将您的通知生成代码发布在您在哪个活动中创建通知的位置吗?
  • 当然,我在第一条消息中发布!
  • 我不是在谈论第一条消息,我是在谈论当您获取 Json 有效负载并生成通知时生成通知的代码。您是否实施了上述解决方案并尝试了我发布的解决方案。

标签: android json firebase logcat firebase-notifications


【解决方案1】:

好的,我刚刚解决了这个问题。

如果您使用的是华为设备,或者使用 emoi 操作系统的设备,请前往

高级设置

比去

电池

受保护的应用程序

然后选择您的应用,将其打开,您将能够在后台接收通知!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-21
    • 2013-10-06
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多