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 :
Users Yesterday :
This Month :
This Year :
Total Users : 192632
Views Today :
Total views :
Who's Online :
Recent Comments