Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Context ctx = TheGameApplication.getAppContext();
- Intent intent = new Intent(ctx, LoginActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
- PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, intent, 0);
- NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx, ctx.getString(R.string.default_channel_id))
- .setSmallIcon(R.drawable.thegame)
- .setPriority(NotificationCompat.PRIORITY_DEFAULT)
- .setAutoCancel(true)
- .setContentIntent(pendingIntent)
- .setWhen(System.currentTimeMillis())
- .setSound(Uri.parse("android.resource://" + ctx.getPackageName() + "/" + R.raw.annoy1))
- .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
- NotificationManagerCompat notificationManager = NotificationManagerCompat.from(ctx);
- // HERE is additional code that has nothing to do with the notification and thus is removed
- notify = !TheGameApplication.get_game_list_in_foreground();
- if (notify) {
- Intent acceptIntent = new Intent(ctx, GameActivity.class);
- acceptIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
- acceptIntent.setAction(ctx.getString(R.string.broadcast_accept));
- acceptIntent.putExtra(ctx.getString(R.string.extra_notification_id), notificationId);
- acceptIntent.putExtra(ctx.getString(R.string.extra_from_username), fromUsername);
- PendingIntent acceptPendingIntent = PendingIntent.getBroadcast(ctx, 0, acceptIntent, 0);
- mBuilder.addAction(R.mipmap.accept, "Accept", acceptPendingIntent);
- Intent rejectIntent = new Intent(ctx, GameActivity.class);
- rejectIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
- rejectIntent.setAction(ctx.getString(R.string.broadcast_reject));
- rejectIntent.putExtra(ctx.getString(R.string.extra_notification_id), notificationId);
- rejectIntent.putExtra(ctx.getString(R.string.extra_from_username), fromUsername);
- PendingIntent rejectPendingIntent = PendingIntent.getBroadcast(ctx, 0, acceptIntent, 0);
- mBuilder.addAction(R.mipmap.reject, "Reject", rejectPendingIntent);
- mBuilder.setContentTitle("Friendship request");
- mBuilder.setContentText(fromUsername + " wants to be your friend. Do you want to ruin your friendship?");
- }
Add Comment
Please, Sign In to add comment