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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 Android 中單擊 Firebase 通知時(shí)將數(shù)據(jù)發(fā)送到活動(dòng)

在 Android 中單擊 Firebase 通知時(shí)將數(shù)據(jù)發(fā)送到活動(dòng)

泛舟湖上清波郎朗 2021-10-20 11:38:28
在我的應(yīng)用程序中,我想使用fireBase進(jìn)行通知。我想當(dāng)點(diǎn)擊通知時(shí)(當(dāng)應(yīng)用程序關(guān)閉時(shí),我的意思是應(yīng)用程序是background)將數(shù)據(jù)發(fā)送putExtra到mainActivity。我下面寫(xiě)的代碼,但點(diǎn)擊時(shí)通知(在應(yīng)用程序是背景),但讓我空了getStringExtra!MyNotificationManager 類(lèi):public class MyNotificationManager {    private Context mCtx;    private Uri soundUri;    private static MyNotificationManager mInstance;    public MyNotificationManager(Context context) {        mCtx = context;    }    public static synchronized MyNotificationManager getInstance(Context context) {        if (mInstance == null) {            mInstance = new MyNotificationManager(context);        }        return mInstance;    }    public void displayNotification(String title, String body) {        soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);        Intent intent = new Intent(mCtx, MainActivity.class);        intent.putExtra("fcm_notification", "Y");        PendingIntent pendingIntent = PendingIntent.getActivity(mCtx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx, Constants.NOTIF_CHANNEL_ID)                .setSmallIcon(R.mipmap.ic_launcher)                .setContentTitle(title)                .setSound(soundUri)                .setAutoCancel(true)                .setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400})                .setContentText(body)                .setContentIntent(pendingIntent);        NotificationManager mNotifyMgr = (NotificationManager) mCtx.getSystemService(NOTIFICATION_SERVICE);        if (mNotifyMgr != null) {            mNotifyMgr.notify(1, mBuilder.build());        }    }}當(dāng)點(diǎn)擊通知(在應(yīng)用程序是后臺(tái))時(shí),在這一行中向我顯示空消息ToastString value = getIntent().getStringExtra("fcm_notification");我該如何解決?
查看完整描述

2 回答

?
慕村9548890

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

從控制臺(tái)發(fā)送通知時(shí),從“高級(jí)選項(xiàng)”添加自定義數(shù)據(jù):

http://img1.sycdn.imooc.com//616f8f59000101d709280372.jpg

出于某種原因,firebase 不允許密鑰以 fcm 開(kāi)頭。您不能使用fcm_notification. 使用不同的鍵。

對(duì)于上圖,按如下方式接收密鑰:

String value = getIntent().getStringExtra("test_key");


查看完整回答
反對(duì) 回復(fù) 2021-10-20
?
幕布斯6054654

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超7個(gè)贊

嘗試這個(gè):


Intent intent = new Intent(mCtx, MainActivity.class);

intent.putExtra("EXTRA_DATA", title);

并獲得:


String value = getIntent().getStringExtra("EXTRA_DATA");

最好換鑰匙。此外,您似乎需要從控制臺(tái)發(fā)送數(shù)據(jù),然后將數(shù)據(jù)發(fā)送到另一個(gè)Activity.


我已經(jīng)使用當(dāng)前通知title來(lái)檢查它是否返回標(biāo)題。如果它返回了值,那么,嘗試從控制臺(tái)發(fā)送數(shù)據(jù)。


查看完整回答
反對(duì) 回復(fù) 2021-10-20
  • 2 回答
  • 0 關(guān)注
  • 170 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號(hào)

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