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 : 14
Users Yesterday : 413
This Month : 8198
This Year : 79771
Total Users : 144258
Views Today : 14
Total views : 647845
Who's Online : 2
Recent Comments