第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在android中自定義通知

如何在android中自定義通知

慕斯王 2023-06-21 13:23:20
我剛剛使用主題消息傳遞實現(xiàn)了 firebase 云消息傳遞 pushNotification。收到通知,但 MyFirebaseMessagingService 未正常工作。它傳遞消息的方式與云消息傳遞相同。完成云消息功能。創(chuàng)建一個名為 MyFirebaseMessagingService 的服務(wù)并使用 FirebaseMessagingService 進(jìn)行擴(kuò)展。將服務(wù)添加到清單。這是我的 FirebaseMessagingService 類。@Overridepublic void onDeletedMessages() {    super.onDeletedMessages();}@Overridepublic void onMessageReceived(RemoteMessage remoteMessage) {    super.onMessageReceived(remoteMessage);    String messageTitle = remoteMessage.getNotification().getTitle();    String clickAction = remoteMessage.getNotification().getClickAction();    Uri soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"+ getApplicationContext().getPackageName() + "/" + R.raw.hollow);    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.default_notification_channel_id))            .setSmallIcon(R.mipmap.ic_launcher_round)            .setContentTitle("New Notification")            .setSound(soundUri)            .setContentText(messageTitle);    Intent resultIntent = new Intent(clickAction);    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);    builder.setContentIntent(pendingIntent);    builder.setPriority(Notification.PRIORITY_HIGH);    if (Build.VERSION.SDK_INT >= 21) builder.setVibrate(new long[0]);    int mNotificationId = (int) System.currentTimeMillis();    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);    notificationManager.notify(mNotificationId, builder.build());}我的清單文件:-<service            android:name=".MyFirebaseMessagingService"            android:exported="true">            <intent-filter>            <action android:name="com.google.firebase.MESSAGING_EVENT"/>            </intent-filter>        </service>        <meta-data            android:name="com.google.firebase.messaging.default_notification_channel_id"            android:value="@string/default_notification_channel_id" />
查看完整描述

1 回答

?
慕村225694

TA貢獻(xiàn)1880條經(jīng)驗 獲得超4個贊

在發(fā)送云消息時,您還必須訂閱要接收通知的主題,例如。


FirebaseMessaging.getInstance().subscribeToTopic("general")

                .addOnCompleteListener(task -> {

                    if (task.isSuccessful())

                        Toast.makeText(this, "Subs-Successful", Toast.LENGTH_SHORT).show();

                    else

                        Toast.makeText(this, "Subs NOT Successful", Toast.LENGTH_SHORT).show();

                });

在此,我訂閱了常規(guī)主題,并且只會收到關(guān)于該主題發(fā)送的消息,如下所示。

http://img1.sycdn.imooc.com//649289a70001a8a104840251.jpg

希望這有幫助......對我有用!



查看完整回答
反對 回復(fù) 2023-06-21
  • 1 回答
  • 0 關(guān)注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號