Guest User

Untitled

a guest
May 27th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. Context ctx = TheGameApplication.getAppContext();
  2.  
  3. Intent intent = new Intent(ctx, LoginActivity.class);
  4. intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
  5. PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, intent, 0);
  6.  
  7. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx, ctx.getString(R.string.default_channel_id))
  8. .setSmallIcon(R.drawable.thegame)
  9. .setPriority(NotificationCompat.PRIORITY_DEFAULT)
  10. .setAutoCancel(true)
  11. .setContentIntent(pendingIntent)
  12. .setWhen(System.currentTimeMillis())
  13. .setSound(Uri.parse("android.resource://" + ctx.getPackageName() + "/" + R.raw.annoy1))
  14. .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
  15. NotificationManagerCompat notificationManager = NotificationManagerCompat.from(ctx);
  16.  
  17. // HERE is additional code that has nothing to do with the notification and thus is removed
  18.  
  19. notify = !TheGameApplication.get_game_list_in_foreground();
  20. if (notify) {
  21.  
  22. Intent acceptIntent = new Intent(ctx, GameActivity.class);
  23. acceptIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
  24. acceptIntent.setAction(ctx.getString(R.string.broadcast_accept));
  25. acceptIntent.putExtra(ctx.getString(R.string.extra_notification_id), notificationId);
  26. acceptIntent.putExtra(ctx.getString(R.string.extra_from_username), fromUsername);
  27. PendingIntent acceptPendingIntent = PendingIntent.getBroadcast(ctx, 0, acceptIntent, 0);
  28. mBuilder.addAction(R.mipmap.accept, "Accept", acceptPendingIntent);
  29.  
  30. Intent rejectIntent = new Intent(ctx, GameActivity.class);
  31. rejectIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
  32. rejectIntent.setAction(ctx.getString(R.string.broadcast_reject));
  33. rejectIntent.putExtra(ctx.getString(R.string.extra_notification_id), notificationId);
  34. rejectIntent.putExtra(ctx.getString(R.string.extra_from_username), fromUsername);
  35. PendingIntent rejectPendingIntent = PendingIntent.getBroadcast(ctx, 0, acceptIntent, 0);
  36. mBuilder.addAction(R.mipmap.reject, "Reject", rejectPendingIntent);
  37.  
  38. mBuilder.setContentTitle("Friendship request");
  39. mBuilder.setContentText(fromUsername + " wants to be your friend. Do you want to ruin your friendship?");
  40. }
Add Comment
Please, Sign In to add comment