Untuk menampilkan notification pada android cukup mudah, berikut adalah program:
private void SetNotification() {
notifManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.ic_launcher;
CharSequence show = "Running";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, show, when);
CharSequence title = "Notification";
CharSequence text = "Test notification";
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this,0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, text, contentIntent);
notifManager.notify(NOTIFICATION_EX, notification);
}
Panggil setNotification() pada onCreate(). Agar program keluar ketika menekan tombol back, tambahkan syntax berikut:
@Override
protected void onPause() {
super.onPause();
if (isFinishing()) {
notifManager.cancel(NOTIFICATION_EX);
}
}
Berikut adalah source code lengkapnya:






Users Today : 187
Users Yesterday : 346
This Month : 533
This Year : 93431
Total Users : 157918
Views Today : 521
Total views : 698164
Who's Online : 2
Recent Comments