简体   繁体   English

Android,FireBase 云消息传递,(FCM)

[英]Android, FireBase Cloud Messaging, (FCM)

我正在使用 FCM 和数据消息传递,可以处理前台和后台通知,但在手机重新启动或应用程序被终止时无法接收它们(任务通过在任务管理器中滑动终止)。

Manifest:显现:

 <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.tadad.firebasetestDOUBLE">
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
        <uses-permission android:name="android.permission.WAKE_LOCK" />

        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

        <application
            android:name="com.example.tadad.firebasetestDOUBLE.AndroidApplication"
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity
                android:name="com.example.tadad.firebasetestDOUBLE.MainActivity"
                android:label="@string/app_name"
                android:theme="@style/AppTheme.NoActionBar">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <!-- Notification -->
            <service
                android:name="com.example.tadad.firebasetestDOUBLE.notification.SomeInstanceIDListenerService">
                <intent-filter>
                    <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
                </intent-filter>
            </service>
            <service
                android:name="com.example.tadad.firebasetestDOUBLE.notification.SomeFirebaseMessagingService">
                <intent-filter>
                    <action android:name="com.google.firebase.MESSAGING_EVENT" />
                </intent-filter>
            </service>
        </application>

    </manifest>

Code:代码:

public class SomeFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        int a = 4;

        sendNotification("Smth", "Receive please!");

    }
}
public class SomeInstanceIDListenerService extends FirebaseInstanceIdService {

    @Override
    public void onTokenRefresh() {
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        sendRegistrationToServer(refreshedToken);
    }

    private void sendRegistrationToServer(String token) {
        // TODO: Implement this method to send token to your app server.
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:订阅 Firebase 云消息传递 (FCM) 主题 - Android: Subscribe to Firebase Cloud Messaging(FCM) Topic 使用 FCM(Firebase 云消息传递)通过 C# 将推送发送到 Android - Send push to Android by C# using FCM (Firebase Cloud Messaging) Android Firebase Cloud Messaging(FCM):subscribeToTopic会自动重试吗? - Android Firebase Cloud Messaging(FCM): Will subscribeToTopic do automatic retries? Android Firebase 云消息传递令牌 (FCM) 令牌太短/不完整 - Android Firebase Cloud Messaging Token (FCM) token is too short/incomplete 在Android上实施FCM(Firebase Cloud Messaging)后,应用在启动时崩溃了吗? - App crashing on launch after the implementation of FCM(Firebase Cloud Messaging) on android? 如何解析Android中的Json数据for Firebase Cloud Messaging(FCM) - How to parse Json data in android for Firebase Cloud Messaging (FCM) Firebase 云消息传递 (FCM) 不适用于低于 kitkat (4.4) 的 android 版本 - Firebase cloud messaging(FCM) not working on android version below kitkat (4.4) Firebase 云消息传递:FCM 令牌到期 - Firebase Cloud Messaging : Expiration of FCM token addCompleteListener()尚未解决-Firebase Cloud Messaging(FCM) - addCompleteListener() is not being resolved - Firebase Cloud Messaging (FCM) Kotlin:订阅Firebase云消息(FCM)专题 - Kotlin: Subscribe to Firebase Cloud Messaging(FCM) Topic
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM