Permalink
Browse files

Add custom actions and cancel the notification

  • Loading branch information...
adamjodlowski committed Jun 19, 2016
1 parent 5b7b979 commit 8162852f8f5fa2cb39152a393ef82f4a57695988
@@ -1,5 +1,6 @@
package io.github.adamjodlowski.notifications;
import android.app.NotificationManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
@@ -12,5 +13,8 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_details);
Log.d("PLAYGROUND", "Details ID: " + getIntent().getIntExtra("EXTRA_DETAILS_ID", -1));
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(MainActivity.NOTIFICATION_ID);
}
}
@@ -12,7 +12,7 @@
public class MainActivity extends AppCompatActivity {
private Button button;
private int notificationId = 1;
public static int NOTIFICATION_ID = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -43,12 +43,14 @@ public void onClick(View view) {
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle("Something important happened")
.setContentText("See the details")
.setAutoCancel(true)
.setContentIntent(detailsPendingIntent)
.setAutoCancel(true);
.addAction(android.R.drawable.ic_menu_compass, "Details", detailsPendingIntent)
.addAction(android.R.drawable.ic_menu_directions, "Show Map", detailsPendingIntent);
// Obtain NotificationManager system service in order to show the notification
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, mBuilder.build());
notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
};

0 comments on commit 8162852

Please sign in to comment.