应用程序不显示Firebase通知(广播意图回调:结果= CANCELED forIntent) [英] App doesn't show firebase notifications (broadcast intent callback: result=CANCELLED forIntent)

查看:197
本文介绍了应用程序不显示Firebase通知(广播意图回调:结果= CANCELED forIntent)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序被杀或处于后台时,我无法收到我的Firebase通知。



我签署了APK,并且它不起作用。发送我的数据通知与JSON的logcat显示我这个错误:

$ p $广播意图回调:结果= CANCELED forIntent {act = com。 google.android.c2dm.intent.RECEIVE pkg = com.example.paolomazza.firebasedemo3(还有额外)}



<鉴于下面的清单,这个bug的原因是什么?
在此先感谢

 <?xml version =1.0encoding =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/>

应用程序$ b $ 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>

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

< activity android:name =。MainActivity>
< intent-filter>

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

< service android:name =。FirebaseIDService>
< intent-filter>
android:stopWithTask =false/>
< / intent-filter>
< / service>

< service android:name =。MyFirebaseMessagingService>
< intent-filter>
android:stopWithTask =false/>
< / intent-filter>
< / service>
< / application>



这里显示的代码通知

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

//你可以在这里得到你的短信。
String text = data.get(my_custom_key);

System.out.println(text);
通知(文字);

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


解决方案

问题。



如果您使用华为设备或使用EMOI os的设备,请转至


高级设置


比去


电池




保护的应用程序

比选择您的应用程序,打开它,您将能够收到您的通知在后台!


I can't receive my Firebase Notifications when the app is killed or in background.

I signed the APK, and it doesn't work, and when I send my Data notification with JSON the logcat shows me this error:

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

Given the following Manifest, what could be the cause of this bug? Thanks in Advance

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

And here's the code for showing the notifications

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

解决方案

OK, I just solved the problem.

If you're using a Huawei device, or a device that uses a EMOI os, just go to

Advanced settings

than go to

Battery

and

Protected Apps

than select your app, switch it on and you'll be able to receive your notifications in the background!

这篇关于应用程序不显示Firebase通知(广播意图回调:结果= CANCELED forIntent)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆