日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java推送数据给安卓,java – 如何从Firebase推送通知中获取数据并将其显示在Android Activity中?...

發(fā)布時間:2023/12/10 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java推送数据给安卓,java – 如何从Firebase推送通知中获取数据并将其显示在Android Activity中?... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

對不起這個noob問題,我是

android開發(fā)的新手.我目前正在開發(fā)一個項目,需要向安裝了我的應(yīng)用程序的

Android設(shè)備發(fā)送推送通知.我已經(jīng)按照firebase的快速入門教程完成了這項工作,并在我的設(shè)備上成功收到了通知.

問題:如何檢索服務(wù)器發(fā)送的消息并將該消息顯示給我的Android Activity?提前致謝.

繼承我的代碼. MainActivity.java

public class MainActivity extends AppCompatActivity {

TextView textView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

TextView tv = (TextView) findViewById(R.id.tv);

/*

* Get the data from push notification and display it in TextView

* */

tv.setText("Message retrieve from Push Notification");

}

這是我的MyFirebaseMessagingService.java

@Override

public void onMessageReceived(RemoteMessage remoteMessage) {

sendNotification(remoteMessage.getNotification().getBody());

}

//This method is only generating push notification

//It is same as we did in earlier posts

public void sendNotification(String messageBody) {

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

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,

PendingIntent.FLAG_ONE_SHOT);

Intent notificationIntent = new Intent(this, MainActivity.class);

notificationIntent.putExtra("message", messageBody);

// set intent so it does not start a new activity

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |

Intent.FLAG_ACTIVITY_SINGLE_TOP);

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)

.setSmallIcon(R.mipmap.ic_launcher)

.setContentTitle("Peoplelink Push Notification")

.setContentText(messageBody)

.setAutoCancel(true)

.setSound(defaultSoundUri)

.setContentIntent(pendingIntent);

NotificationManager notificationManager =

(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0, notificationBuilder.build());

}

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的java推送数据给安卓,java – 如何从Firebase推送通知中获取数据并将其显示在Android Activity中?...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。