【发布时间】:2017-06-26 09:23:54
【问题描述】:
我已经使用我自己的服务器成功地将 Firebase 通知发送到 android 应用程序,并且我在单击通知的新活动中的列表视图中列出了消息。我的问题是如果我点击一个特定的通知,所有未读的通知消息都会显示在列表视图中
FirebaseMessageservice.java
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");
list.add(message);
Collections.reverse(list);
System.out.println(list);
MyNotificationManager mNotificationManager = new MyNotificationManager(getApplicationContext());
Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
//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
public class HomeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ListView listView = (ListView) findViewById(R.id.notification_list);
adapter = new ListViewAdapter(this, list);
listView.setAdapter(adapter);
}
}
输出屏幕
如果我点击 Hello Mom,它会移动到带有列表视图的下一个活动,但两条消息都显示为“1. Mom 2. Dad”
【问题讨论】:
-
第一种方法应该叫showNotification还是sendPushNotication?
标签: java android json listview firebase-cloud-messaging