File tree 1 file changed +15
-1
lines changed
app/src/main/java/io/github/adamjodlowski/notifications
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1
1
package io .github .adamjodlowski .notifications ;
2
2
3
+ import android .app .NotificationManager ;
3
4
import android .os .Bundle ;
5
+ import android .support .v4 .app .NotificationCompat ;
4
6
import android .support .v7 .app .AppCompatActivity ;
5
7
import android .view .View ;
6
8
import android .widget .Button ;
7
9
8
10
public class MainActivity extends AppCompatActivity {
9
11
10
12
private Button button ;
13
+ private int notificationId = 1 ;
11
14
12
15
@ Override
13
16
protected void onCreate (Bundle savedInstanceState ) {
@@ -20,7 +23,18 @@ protected void onCreate(Bundle savedInstanceState) {
20
23
private View .OnClickListener buttonClickListener = new View .OnClickListener () {
21
24
@ Override
22
25
public void onClick (View view ) {
23
- // TODO display notification
26
+
27
+ // NotificationCompat Builder takes care of backwards compatibility and
28
+ // provides clean API to create rich notifications
29
+ NotificationCompat .Builder mBuilder = new NotificationCompat .Builder (MainActivity .this )
30
+ .setSmallIcon (android .R .drawable .ic_dialog_info )
31
+ .setContentTitle ("Notification title" )
32
+ .setContentText ("Content text" );
33
+
34
+ // Obtain NotificationManager system service in order to show the notification
35
+ NotificationManager notificationManager = (NotificationManager ) getSystemService (NOTIFICATION_SERVICE );
36
+ notificationManager .notify (notificationId , mBuilder .build ());
37
+
24
38
}
25
39
};
26
40
}
You can’t perform that action at this time.
0 commit comments