इस नोब सवाल के लिए खेद है, मैं एंड्रॉइड विकास के लिए नया हूँ। मैं वर्तमान में एक प्रोजेक्ट पर काम कर रहा हूं जिसके लिए एक एंड्रॉइड डिवाइस पर पुश अधिसूचना भेजने की आवश्यकता है जहां मेरा ऐप इंस्टॉल है। मैंने फ़ायरबेस द्वारा त्वरित स्टार्ट ट्यूटोरियल का पालन करके इसे पहले ही किया है और मुझे अपने डिवाइस पर अधिसूचना सफलतापूर्वक प्राप्त हुई है।फायरबेस पुश अधिसूचना से डेटा कैसे प्राप्त करें और इसे अपने एंड्रॉइड गतिविधि में प्रदर्शित करें?
प्रश्न: मैं सर्वर द्वारा भेजे गए संदेश को कैसे पुनर्प्राप्त कर सकता हूं और उस संदेश को मेरी एंड्रॉइड गतिविधि में प्रदर्शित कर सकता हूं? अग्रिम में धन्यवाद।
मेरा कोड है। 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());
}
हाय में, किसी को भी मुझे tihs साथ कर सकते हैं। – Daryll