相关疑难解决方法(0)

当应用程序在后台时,不会调用Firebase onMessageReceived

我正在使用Firebase,并在应用程序处于后台时测试从我的服务器向我的应用发送通知.通知成功发送,甚至出现在设备的通知中心,但是当通知出现或甚至我点击它时,我的FCMessagingService内的onMessageReceived方法永远不会被调用.

当我在我的应用程序位于前台时对此进行测试时,调用了onMessageReceived方法,一切正常.当应用程序在后台运行时会出现此问题.

这是预期的行为,还是有办法解决这个问题?

这是我的FBMessagingService:

import android.util.Log;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

public class FBMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.i("PVL", "MESSAGE RECEIVED!!");
        if (remoteMessage.getNotification().getBody() != null) {
            Log.i("PVL", "RECEIVED MESSAGE: " + remoteMessage.getNotification().getBody());
        } else {
            Log.i("PVL", "RECEIVED MESSAGE: " + remoteMessage.getData().get("message"));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-cloud-messaging

201
推荐指数
15
解决办法
16万
查看次数

为什么PendingIntent不会为Intent发回我的自定义Extras设置?

这个问题在某种程度上与我想要在startActivityForResult中获得额外内容的问题有关,但现在我面临另一个挑战.

我已订阅接收ProximityAlerts,我已明确构建Intent以包含一些Extras.但是当我得到服务时,额外的东西不存在.

这里的答案是工作代码:

Intent intent = new Intent(this, PlacesProximityHandlerService.class);
intent.setAction("PlacesProximityHandlerService");
intent.putExtra("lat", objPlace.getLat());
intent.putExtra("lon", objPlace.getLon());
intent.putExtra("error_m", objPlace.getError()+ALERT_RANGE_IN_METERS);
PendingIntent sender=PendingIntent.getService(this, 0, intent, 0);
LocationUtils.addProximity(this, objPlace.getLat(), objPlace.getLon(),objPlace.getError()+ALERT_RANGE_IN_METERS, -1, sender);
Run Code Online (Sandbox Code Playgroud)

文档说param PendingIntent to be sent for each location update

android extras android-intent

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