Skip to content

Commit 40d017d

Browse files
committed
Notification App
Display Notification on top bar of an App when Opened learnt about Notification
1 parent 6d95177 commit 40d017d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: notification/MainActivity.java

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.lenovo.notification;
2+
3+
import android.app.Notification;
4+
import android.app.NotificationManager;
5+
import android.app.PendingIntent;
6+
import android.content.Intent;
7+
import android.support.v7.app.AppCompatActivity;
8+
import android.os.Bundle;
9+
10+
public class MainActivity extends AppCompatActivity {
11+
12+
@Override
13+
protected void onCreate(Bundle savedInstanceState) {
14+
super.onCreate(savedInstanceState);
15+
setContentView(R.layout.activity_main);
16+
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
17+
18+
19+
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),1,intent,0);
20+
Notification notification = new Notification.Builder(getApplicationContext())
21+
.setContentTitle("Lunch is ready!!")
22+
.setContentText("it'sgetting late....")
23+
.setContentIntent(pendingIntent)
24+
.addAction(android.R.drawable.sym_action_chat,"Chat",pendingIntent)
25+
.setSmallIcon(android.R.drawable.sym_def_app_icon)
26+
.build();
27+
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
28+
notificationManager.notify(1,notification);
29+
}
30+
}

0 commit comments

Comments
 (0)