Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Show basic notification
  • Loading branch information
adamjodlowski committed Jun 19, 2016
1 parent c42406c commit 407bc2d
Showing 1 changed file with 15 additions and 1 deletion.
@@ -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) {
Expand All @@ -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.