Skip to content

Commit

Permalink
Add custom actions and cancel the notification
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjodlowski committed Jun 19, 2016
1 parent 5b7b979 commit 8162852
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
@@ -1,5 +1,6 @@
package io.github.adamjodlowski.notifications; package io.github.adamjodlowski.notifications;


import android.app.NotificationManager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
Expand All @@ -12,5 +13,8 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_details); setContentView(R.layout.activity_details);


Log.d("PLAYGROUND", "Details ID: " + getIntent().getIntExtra("EXTRA_DETAILS_ID", -1)); Log.d("PLAYGROUND", "Details ID: " + getIntent().getIntExtra("EXTRA_DETAILS_ID", -1));

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(MainActivity.NOTIFICATION_ID);
} }
} }
Expand Up @@ -12,7 +12,7 @@
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {


private Button button; private Button button;
private int notificationId = 1; public static int NOTIFICATION_ID = 1;


@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -43,12 +43,14 @@ public void onClick(View view) {
.setSmallIcon(android.R.drawable.ic_dialog_info) .setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle("Something important happened") .setContentTitle("Something important happened")
.setContentText("See the details") .setContentText("See the details")
.setAutoCancel(true)
.setContentIntent(detailsPendingIntent) .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 // Obtain NotificationManager system service in order to show the notification
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, mBuilder.build()); notificationManager.notify(NOTIFICATION_ID, mBuilder.build());


} }
}; };
Expand Down

0 comments on commit 8162852

Please sign in to comment.