Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final String TAG = "MyFMService";
- public boolean isAppOpened = true;
- public static boolean notificationReceived = false;
- Bundle b;
- @Override
- public void onMessageReceived(RemoteMessage remoteMessage) {
- Log.d(TAG, "FCM Message Id: " + remoteMessage.getMessageId());
- Log.d(TAG, "FCM Notification Message: " +
- remoteMessage.getNotification());
- Log.d(TAG, "FCM Data Message: " + remoteMessage.getData());
- showNotification(remoteMessage.getData());
- }
- public void showNotification(Map<String,String> r) {
- try {
- Intent intent;
- try {
- SessionContext.createSessionFromCurrentSession();
- }catch (IllegalStateException e){
- isAppOpened=false;
- }
- if (isAppOpened) {
- notificationReceived=true;
- if (!(r.get("type").equals("0"))) {
- Notifications.notificationId = Long.parseLong(r.get("notificationId"));
- NewPost.postType = (SessionContext.getUserId() ==
- Long.parseLong(r.get("postedUserId"))) ?
- getResources().getString(R.string.post_type_my_post) :
- getResources().getString(R.string.post_type_relevant_post);
- Map<String, Object> postMap = new HashMap<>();
- postMap.put("threadId", r.get("threadId"));
- postMap.put("profileUrl", r.get("profileUrl"));
- postMap.put("firstName", r.get("firstName"));
- postMap.put("lastName", r.get("lastName"));
- postMap.put("categoryId", r.get("categoryId"));
- postMap.put("timestamp", Long.parseLong(r.get("timeStamp")));
- postMap.put("subject", r.get("subject"));
- postMap.put("threadStatus", r.get("threadStatus"));
- postMap.put("userId", String.valueOf(SessionContext.getUserId()));
- postMap.put("postedUserId", r.get("postedUserId"));
- postMap.put("userName", r.get("userName"));
- ViewThread.post = new Post(postMap);
- NewPost.currentPostId = ViewThread.post.getThreadId();
- NewPost.currentPosition = (SessionContext.getUserId() ==
- Long.parseLong(r.get("postedUserId"))) ? 0 : 1;
- NewPost.postedUserId = Long.parseLong(ViewThread.post.getPostedUserId());
- HomeScreen.categoryId = Long.parseLong(ViewThread.post.getCategoryId());
- intent = new Intent(this, ViewThread.class);
- intent.putExtra("THREAD", ViewThread.post);
- // startActivity(intent);
- } else {
- intent = new Intent(this, Notifications.class);
- }
- } else {
- notificationReceived=true;
- intent = new Intent(this, SplashScreen.class);
- }
- PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
- NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
- .setContentTitle("New Notification")
- .setContentText(r.get("notification"))
- .setSmallIcon(R.drawable.d4e_logo)
- .setContentIntent(pIntent)
- .setAutoCancel(true)
- .addAction(R.drawable.view_icon, "View", pIntent);
- /* .addAction(R.drawable.icon, "More", pIntent)
- .addAction(R.drawable.icon, "And more", pIntent).build();*/
- NotificationManager notificationManager =
- (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- notificationManager.notify(0, builder.build());
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment