Guest User

MainActivity.java

a guest
Feb 12th, 2017
17,886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1.  public void tampilNotification(View view) {
  2.  
  3.  Intent intent = new Intent(Intent.ACTION_VIEW,
  4.                 Uri.parse("http://www.okedroid.com/"));
  5.         //menginisialiasasi intent
  6.         PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
  7.         //untuk memanggil activity di Notification
  8.         /*
  9. Menmbangun atau mensetup Notification dengan NotificationCompat.Builder
  10.  */
  11.         NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
  12.                 .setSmallIcon(R.mipmap.ic_launcher) //ikon notification
  13.                 .setContentTitle("1 Postingan Baru")//judul konten
  14.                 .setContentIntent(pendingIntent)//memanggil object pending intent
  15.                 .setAutoCancel(true)//untuk menswipe atau menghapus notification
  16.                 .setContentText("Kunjungi blog okedroid.com"); //isi text
  17.  
  18. /*
  19. Kemudian kita harus menambahkan Notification dengan menggunakan NotificationManager
  20.  */
  21.  
  22.         NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  23.  
  24.         notificationManager.notify(NOTIFICATION_ID, builder.build()
  25.         );
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment