Permalink
Browse files

Show basic notification

  • Loading branch information...
adamjodlowski committed Jun 19, 2016
1 parent c42406c commit 407bc2d3e16d4dd5d3de1f167a660cca54b44a28
Showing with 15 additions and 1 deletion.
  1. +15 −1 app/src/main/java/io/github/adamjodlowski/notifications/MainActivity.java
@@ -1,13 +1,16 @@
package io.github.adamjodlowski.notifications;
import android.app.NotificationManager;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button button;
private int notificationId = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -20,7 +23,18 @@ protected void onCreate(Bundle savedInstanceState) {
private View.OnClickListener buttonClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO display notification
// NotificationCompat Builder takes care of backwards compatibility and
// provides clean API to create rich notifications
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.this)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle("Notification title")
.setContentText("Content text");
// Obtain NotificationManager system service in order to show the notification
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, mBuilder.build());
}
};
}

0 comments on commit 407bc2d

Please sign in to comment.