If you want to create Status bar Notification you can use my below code. Notification are used to alert users on some events that requires their attention. The NotificationManger is service used to manage Notification. In below code i have also used getSystemService()method it shows active task or application on your mobile. See the below example it will clearly described you how to make Status bar Notification .
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button notificationButton = (Button) findViewById(R.id.notificationButton);
notificationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Notify("Title: Meeting with Business",
"Msg:Pittsburg 11:00 AM EST ");
}
});
}
@SuppressWarnings("deprecation")
private void Notify(String notificationTitle, String notificationMessage) {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
@SuppressWarnings("deprecation")
Notification notification = new Notification(R.drawable.ic_launcher,
"New Message", System.currentTimeMillis());
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(MainActivity.this, notificationTitle,
notificationMessage, pendingIntent);
notificationManager.notify(9999, notification);
}
}
0 Comment(s)