日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

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

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

對不起這個noob問題,我是

android開發的新手.我目前正在開發一個項目,需要向安裝了我的應用程序的

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

問題:如何檢索服務器發送的消息并將該消息顯示給我的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());

}

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。