问题描述
嗨朋友们,
我在推送通知中遇到了一些问题。当我使用我的时候,如果有任何通知,那么消息文本是可见的,但当我的应用程序在后台时,消息文本不会出现。可以帮到这个吗?
谢谢
我的尝试:
public void onMessageReceived(RemoteMessage remoteMessage){
Log.d(TAG,来自:+ remoteMessage.getFrom());
if(remoteMessage.getData()。size()> 0){
Log.d(TAG,消息数据有效负载:+ remoteMessage.getData());
Data = remoteMessage.getData();
message1 = Data.get(message);
note_id = Data.get(NoteId);
l = Long.parseLong(note_id);
DataBaseHelper myDBHelper = new DataBaseHelper(getApplicationContext() );
myDBHelper.open();
objGCM.NOTEID = l;
objGCM.MESSAGE = message1;
i = myDBHelper.InsertgcmRecord(objGCM);
gcmList.add(objGCM);
myDBHelper.clo se();
}
if(remoteMessage.getNotification()!= null){
Log .d(TAG,消息通知正文:+ remoteMessage.getNotification()。getBody());
}
sendNotification(message1);
}
private void sendNotification(String message){
Intent intent = new Intent(this,NotificationList.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,requestID,intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notnullogo)
.setCont entTitle(NotNul)
.setContentText(message1)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setColor(Color.parseColor(#0089C4))
.setStyle(new NotificationCompat.BigTextStyle()。bigText(message1))
.setContentIntent( pendingIntent);
NotificationManager notificationManager =
(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID,notificationBuilder.build());
}
Hi friends,
I am facing some problem in push notification. When i am using my and at that time if any notification is coming then message text is visible, but when my app is in background then message text is not coming. Can any one help for this??
Thanks
What I have tried:
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
Data = remoteMessage.getData();
message1=Data.get("message");
note_id=Data.get("NoteId");
l = Long.parseLong(note_id);
DataBaseHelper myDBHelper = new DataBaseHelper(getApplicationContext());
myDBHelper.open();
objGCM.NOTEID=l;
objGCM.MESSAGE=message1;
i=myDBHelper.InsertgcmRecord(objGCM);
gcmList.add(objGCM);
myDBHelper.close();
}
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
sendNotification(message1);
}
private void sendNotification(String message) {
Intent intent = new Intent(this, NotificationList.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, requestID , intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notnullogo)
.setContentTitle("NotNul")
.setContentText(message1)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setColor(Color.parseColor("#0089C4"))
.setStyle(new NotificationCompat.BigTextStyle().bigText(message1))
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}
推荐答案
这篇关于获取后台应用的通知文本时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!