JSONObject数据具有收到的firebase通知消息。通知堆叠在托盘上。如果我点击通知,应该将特定消息传递给下一个活动。消息的第一个值是"嗨"消息的第二个值是"你好"。我应该将两个值都发送到下一个活动。但只有" Hello"(第二个值)正在下一个活动中打印
private void sendPushNotification(JSONObject json) {
//optionally we can display the json into log
Log.e(TAG, "Notification JSON " + json.toString());
try {
//getting the json data
JSONObject data = json.getJSONObject("data");
//parsing json data
String title = data.getString("title");
String message = data.getString("message");
String imageUrl = data.getString("image");
//creating MyNotificationManager object
MyNotificationManager mNotificationManager = new MyNotificationManager(getApplicationContext());
Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
intent.putExtra("time",message);
//if there is no image
if(imageUrl.equals("null")){
//displaying small notification
mNotificationManager.showSmallNotification(title, message, intent);
}else{
//if there is an image
//displaying a big notification
mNotificationManager.showBigNotification(title, message, imageUrl, intent);
}
} catch (JSONException e) {
Log.e(TAG, "Json Exception: " + e.getMessage());
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
HomeActivity.java
Intent i=getIntent();
String times = i.getStringExtra("time");
答案 0 :(得分:0)
// In Current Activity
Bundle bundle = new Bundle();
bundle.putString("key_hi", "Hi");
bundle.putString("key_hello", "Hello");
Intent intent = new Intent(this, NextActivity.class);
intent.putExtras(bundle);
startActivity(intent);
// In HomeActivity.java
Bundle bundle = getIntent().getExtras();
String strHi = bundle.getString("key_hi");
String strHello = bundle.getString("key_hello");