相关疑难解决方法(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万
查看次数

华为手机上的"受保护的应用程序"设置,以及如何处理它

我有一台带有Android 5.0的华为P8用于测试应用程序.该应用程序需要在后台运行,因为它跟踪BLE区域.

我发现华为内置了一个名为Protected Apps的"功能",可以通过手机设置(电池管理器>受保护的应用程序)进行访问.这允许选定的应用程序在屏幕关闭后继续运行.

对华为来说很明智,但不幸的是,对于我来说,它看起来像是选择加入,即默认情况下应用程序已经关闭,你必须手动将它们放入.这不是一个showstopper,因为我可以在常见问题解答或打印中建议用户关于修复的文档,但我最近安装了Tinder(用于研究目的!),并注意到它被自动放入受保护的列表中.

有谁知道我的应用程序如何做到这一点?它是清单中的设置吗?这是华为为Tinder启用的东西,因为它是一个受欢迎的应用程序?

android android-manifest

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

当Android应用程序从最近的托盘中删除时,Firebase(FCM)通知不会出现

我正在通过我自己的Web服务发送Firebase通知,如下所示.

$url = 'https://fcm.googleapis.com/fcm/send';
        $fields = array(
             'registration_ids' => $tokens,
             'data' => $message
            );
        $headers = array(
            'Authorization:key = SERVER_KEY ',
            'Content-Type: application/json'
            );
Run Code Online (Sandbox Code Playgroud)

1.当App在前台和后台没有任何问题时,通知即将到来,但如果我从最近的托盘中删除应用程序然后通知没有到来,我必须处理这个任何解决方案吗?(就像Whatsup通知显示所有场景甚至我强制停止此应用程序的设置)

2.一旦我收到通知,从"onMessageReceived"如何将这些消息,正文内容传递给我的Activity/Fragments?

3.在某些情况下,我想向所有人发送通知,而不是将所有令牌添加到数组中.任何其他方式处理像"发送给所有"这样的东西?

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = "MsgService";
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d(TAG, "From: " + remoteMessage.getFrom());
        Log.d(TAG, "Data Payload : " + remoteMessage.getData());
        sendNotification(remoteMessage.getData().get("message"));
    }
    private void sendNotification(String messageBody) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);
        Uri …
Run Code Online (Sandbox Code Playgroud)

notifications android android-notifications firebase firebase-cloud-messaging

8
推荐指数
1
解决办法
5564
查看次数