我有一個問題..我怎麼能保存推送通知在textView中我的第二個活動..這是我的代碼。謝謝你的幫助...Firebase在Textview中推送
public class FCM_service extends FirebaseMessagingService {
public static String dato;
String type="";
TextView texto ;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if(remoteMessage.getData().size() >0){
type="json";
sendNotificatio(remoteMessage.getData().toString());
}
if(remoteMessage.getNotification() !=null) {
type = "message";
sendNotificatio(remoteMessage.getNotification().getBody());
}
}
public void sendNotificatio(String messageBody) {
String id="";
String message="";
String titles="";
if (type.equals("json")){
try {
JSONObject jsonObject = new JSONObject(messageBody);
id=jsonObject.getString("id");
message=jsonObject.getString("message");
titles= jsonObject.getString("title");
} catch (JSONException e) {
e.printStackTrace();
}
} else if (type.equals("message")) {
message= messageBody;
}
Intent i = new Intent(FCM_service.this,MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle(titles)
.setContentText(message)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pendingIntent);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(0,builder.build());
Log.d("LOGTA", "NOTIFICACION RECIBIDA");
Log.d("LOGTAG", "Título:" + titles);
Log.d("LOGTAG", "Texto: " + message);
String dato = message;
i.putExtra("MENSAJE", dato);
Log.e("Mensajito", dato);
}
}
我試圖用意圖/捆把消息發送給其他活動......但我總是收到空,異常錯誤..別人的幫助,請
想要保存什麼,數據,消息? –
是布魯諾。我收到服務器消息...,但我想要做的是,在textView中捕獲此服務器消息到我的第二個活動 –