Bu noob sorusu için üzgünüm, android geliştirme konusunda yeniyim. Şu anda uygulamamın yüklü olduğu bir android cihaza push bildirimi göndermesi gereken bir proje üzerinde çalışıyorum. Bunu, hızlı başlangıç eğiticisini firebase tarafından takip ederek yaptım ve cihazımda bildirimi başarıyla aldım.Firebase Push Notification'dan veri nasıl alınır ve Android Etkinliğinizde nasıl görüntülenir?
Soru: Sunucu tarafından gönderilen iletiyi nasıl alabilir ve bu iletiyi Android Etkinliğime nasıl görüntüleyebilirim? Şimdiden teşekkürler.
Heres benim kodum. 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");
}
ve (bir bildirime gösterdi hariç) bazı ek mesaj, ayarlayabilirsiniz göndermek istiyorsanız bu benim 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());
}
Merhaba içinde
Ve kullanmak
EventBus.getDefault().post()
, herkes üreterek bu konuda bana yardımcı olabilir. – Daryll