相关疑难解决方法(0)

如何在Firebase中的后台应用时处理通知

这是我的清单

    <service android:name=".fcm.PshycoFirebaseMessagingServices">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <service android:name=".fcm.PshycoFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
Run Code Online (Sandbox Code Playgroud)

当应用程序处于后台并且通知到达时,默认通知将会运行并且不会运行我的代码onMessageReceived.

这是我的onMessageReceived代码.如果我的应用程序在前台运行,而不是在后台应用程序时,则调用此方法.如何在应用程序处于后台时运行此代码?

// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // TODO(developer): Handle FCM messages here.
    // If the application is in the foreground handle both data and notification messages here.
    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See …
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-cloud-messaging

379
推荐指数
17
解决办法
31万
查看次数

带有新Firebase云消息传递系统的通知图标

昨天谷歌在Google I/O上展示了基于新Firebase的新通知系统.我在Github上尝试了这个新的FCM(Firebase云消息传递)示例.

尽管我已声明了特定的drawable,但通知的图标始终是ic_launcher

为什么?以下是处理邮件的官方代码

public class AppFirebaseMessagingService extends FirebaseMessagingService {

    /**
     * Called when message is received.
     *
     * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
     */
    // [START receive_message]
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // If the application is in the foreground handle both data and notification messages here.
        // Also if you intend on generating your own notifications as a result of a received FCM
        // message, here is where that should …
Run Code Online (Sandbox Code Playgroud)

android push-notification googleio firebase firebase-cloud-messaging

118
推荐指数
5
解决办法
13万
查看次数

收到firebase通知的打开应用程序(FCM)

我希望在收到通知时自动打开应用程序,Firebase和新的FCM通知是否可以实现?

我知道我可以设置click_action,但这只是为了自定义通知点击会启动哪些活动,我需要在收到通知时自动启动的内容.

我尝试了快速启动消息传递firebase示例,并且有一个onMessageReceived()方法,但只有在应用程序位于前台时它才有效.应用程序在后台运行时是否会执行某些操作?GCM可以通过直接启动广播接收器的活动意图来做我喜欢的事情,广播接收器在收到通知时调用.

android firebase firebase-cloud-messaging firebase-notifications

31
推荐指数
3
解决办法
5万
查看次数

升级到Google Play Services 9.0.0后,App会在DynamiteModulesC中挂起

通过以下更改将开发中的应用程序升级到9.0.0并重新生成google-services.json:

classpath 'com.google.gms:google-services:3.0.0'
compile 'com.google.android.gms:play-services:9.0.0'
Run Code Online (Sandbox Code Playgroud)

升级后,当应用程序初始化时,将显示预期的logcat消息序列.大约7秒后,再次输出相同的消息序列,并添加标题background_crash.例如:

17:39:30.162 5453-5453/com.xxx.nub:background_crash I/MultiDex: install done
Run Code Online (Sandbox Code Playgroud)

该应用程序正常运行,直到它变得隐藏,例如通过在另一个应用程序中启动活动.5秒后,系统检测到应用程序已挂起:

05-20 17:40:10.315 5138-5138/com.xxx.nub I/MainActivity: STOP MainActivity
05-20 17:40:10.375 5138-5138/com.xxx.nub I/NubApplication: onTrimMemory(): TRIM_MEMORY_UI_HIDDEN
05-20 17:40:10.375 5138-5138/com.xxx.nub D/FirebaseApp: Notifying background state change listeners.
05-20 17:45:10.465 5138-5143/com.xxx.nub I/dalvikvm: threadid=3: reacting to signal 3
05-20 17:45:10.565 5138-5143/com.xxx.nub I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪显示应用程序已挂起 com.google.android.gms.DynamiteModulesC

----- pid 5138 at 2016-05-20 17:45:10 -----
Cmd line: com.xxx.nub

JNI: CheckJNI is off; workarounds are off; pins=0; globals=295

DALVIK THREADS:
(mutexes: tll=0 …
Run Code Online (Sandbox Code Playgroud)

android google-play-services

15
推荐指数
1
解决办法
4563
查看次数

Firebase推送通知更新数据库

我正在尝试通过新的Firebase推送通知服务向我的用户发送一些数据.

我正在使用"消息文本" - "dbupdate"添加一些"键值"自定义数据项,以检测它是更新消息还是我要向用户显示的正常推送通知.

在我的接收器中,我检查我是否有自定义数据并运行更新,如果为真.如果不是这种情况,我会通过短信显示正常通知.

它仅在我的应用程序打开时有效.如果应用程序关闭,则无论如何都会显示通知,而我的if检查甚至没有运行,

一些代码:

public class PushMessageService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        Map<String,String> data = remoteMessage.getData();
        String link = data.get("link");
        String name = data.get("name");
        if (link!=null) {
            Log.d("link",link);
            Log.d("name",name);
            UpdateHelper.Go(this, link, name);
        }
        else {
            NotificationCompat.Builder mBuilder =
                    new NotificationCompat.Builder(this)
                            .setSmallIcon(R.drawable.ic_shop_white_24dp)
                            .setAutoCancel(true)
                    .setContentTitle(remoteMessage.getNotification().getTitle())
                   .setContentText(remoteMessage.getNotification().getBody());
            NotificationManager mNotificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(5, mBuilder.build());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这里举例说明

为什么会这样?即使应用程序关闭,我该怎么做才能运行我的代码?

android firebase firebase-notifications

6
推荐指数
1
解决办法
1万
查看次数