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

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

如何通過單擊 firebase 通知打開新活動并在文本視圖上打印通知消息

如何通過單擊 firebase 通知打開新活動并在文本視圖上打印通知消息

白板的微信 2022-06-15 15:53:16
我想讓我的 Firebase 通知可點擊。單擊通知后,將打開一個名為 HomeActivity 的新活動,我想在其中將通知消息顯示為文本視圖。我已經(jīng)添加了通知,它運行良好。但是,每當我單擊通知時,它都會返回到 mainActivity 并且不會在 textview 中顯示消息。我嘗試了一些代碼,但它不起作用。這是我的代碼,MyFirebaseInstanceService.classpublic class MyFirebaseInstanceService extends FirebaseMessagingService {@Overridepublic void onMessageReceived(RemoteMessage remoteMessage) {    super.onMessageReceived(remoteMessage);    shownotification(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());    String click_action = remoteMessage.getNotification().getClickAction();    Intent i = new Intent(click_action);    Intent in = new Intent("intentKey");            in.putExtra("key", remoteMessage);    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(in);    Intent intent = new Intent("com.push.message.received");    intent.putExtra("message", remoteMessage);// Add more data as per need    sendBroadcast(intent);}private void shownotification(String title,String body){        NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);        String NOTIFICATION_CHANNEL_ID = "com.example.theroos.simplifiedmsging02.test";        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)        {            NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Notification",NotificationManager.IMPORTANCE_DEFAULT);            notificationChannel.setDescription("SIMPLIFIED");            notificationChannel.setLightColor(Color.BLUE);            notificationChannel.setVibrationPattern(new long[]{0,100,500,1000});            notificationChannel.enableLights(true);            //notificationChannel.createNotificationChannel(notificationChannel);        }        Intent activityintent = new Intent(this,HomeActivity.class);        PendingIntent contentintent = PendingIntent.getActivity(this,0,activityintent,0);}
查看完整描述

2 回答

?
忽然笑

TA貢獻1806條經(jīng)驗 獲得超5個贊

有一些方法可以實現(xiàn)這一目標。但是stackoverflow上有很多類似的問題。

該方法取決于您的 fcm 通知負載。請看這個答案。你會找到你正在尋找的所有東西。

https://stackoverflow.com/a/40185654/7140884


查看完整回答
反對 回復(fù) 2022-06-15
?
BIG陽

TA貢獻1859條經(jīng)驗 獲得超6個贊

一開始你不應(yīng)該同時創(chuàng)建通知和發(fā)送廣播消息。嘗試這個:


        public class MyFirebaseInstanceService extends FirebaseMessagingService {



    @Override

    public void onMessageReceived(RemoteMessage remoteMessage) {

        super.onMessageReceived(remoteMessage);

               NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

        String NOTIFICATION_CHANNEL_ID = "com.example.theroos.simplifiedmsging02.test";


        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)

        {

            NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Notification",NotificationManager.IMPORTANCE_DEFAULT);

            notificationChannel.setDescription("SIMPLIFIED");

            notificationChannel.setLightColor(Color.BLUE);

            notificationChannel.setVibrationPattern(new long[]{0,100,500,1000});

            notificationChannel.enableLights(true);

            //notificationChannel.createNotificationChannel(notificationChannel);


        }


        Intent activityintent = new Intent(this,HomeActivity.class);

        PendingIntent contentintent = PendingIntent.getActivity(this,0,activityintent,0);


        NotificationCompat.Builder notificationbuilder = new NotificationCompat.Builder(this,NOTIFICATION_CHANNEL_ID);


        notificationbuilder.setAutoCancel(true)

                .setDefaults(Notification.DEFAULT_ALL)

                .setWhen(System.currentTimeMillis())

                .setSmallIcon(R.drawable.ic_mode_comment_black_24dp)

                .setContentTitle(title)

                .setContentIntent(contentintent)

                .setContentText(body)

                .setColor(Color.BLUE)

                .setAutoCancel(true)

                .setContentInfo("Info");


        notificationManager.notify(new Random().nextInt(),notificationbuilder.build());


    }

....

然后PendingIntent.getActivity你可以創(chuàng)建PendingIntent.getBroadcast(YourBroadcastReceiver..)你應(yīng)該在清單中注冊的廣播接收器:


<receiver

    android:name="com.app.YourBroadcastReceiver"

    android:enabled="true"

    android:exported="true">

    <intent-filter>

        <action android:name="YourReceiverIntentFilter" />

    </intent-filter>

</receiver>

在YourBroadcastReceiver您應(yīng)該獲得待處理的意圖,然后在您的活動中向您的本地接收器發(fā)送廣播消息。


希望能幫助到你!


查看完整回答
反對 回復(fù) 2022-06-15
  • 2 回答
  • 0 關(guān)注
  • 163 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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