Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Open new activity from notification action using intent
private void openNewActivity(String title, String description){
Intent testIntent = new Intent(this,TestActivity.class);
testIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pen = PendingIntent.getActivity(this,15,testIntent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(title)
.setContentText(description)
.setSmallIcon(R.mipmap.ic_launcher)
.setOngoing(true)
.addAction(R.drawable.ic_play, "Test", pen)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
notificationManagerCompat.notify(5,builder.build());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment