FCM推送通知不适用于Android 7.0

时间:2020-05-09 21:33:07

标签: android firebase push-notification firebase-cloud-messaging

我的android应用程序发布在Play商店上,并且只有android 7.0 没有收到通知。 这是我正在使用的代码 Manifest.xml

    <activity android:name=".ui.notifications.MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </activity>

NotificationHelper

public class NotificationHelper {

    public static final String Channel_ID = "CodeGenix";
    public static final String Channel_NAME = "PrimeNet";
    public static final String Channel_Des = "One Connection, ONe Solution";

    public static void displayNotification(Context context, String title, String body) {
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context, Channel_NAME)
                        .setSmallIcon(R.drawable.ic_launcher)
                        .setContentTitle(title)
                        .setContentText(body)
                        .setPriority(NotificationCompat.PRIORITY_DEFAULT);

        NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context);
        mNotificationManager.notify(1, mBuilder.build());
    }
}

MyFirebaseMessagingService

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);

        if (remoteMessage.getNotification()!= null){
            String title = remoteMessage.getNotification().getTitle();
            String body = remoteMessage.getNotification().getBody();

            NotificationHelper.displayNotification(getApplicationContext(),title,body);
        }
    }
}

0 个答案:

没有答案
相关问题