tegarkurniawan

notif

Mar 14th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. public void showSmallNotification(String title, String message, Intent intent, String url) {
  2. PendingIntent resultPendingIntent =
  3. PendingIntent.getActivity(
  4. mCtx,
  5. ID_SMALL_NOTIFICATION,
  6. intent,
  7. PendingIntent.FLAG_UPDATE_CURRENT
  8. );
  9.  
  10. Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  11. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx);
  12. Notification notification;
  13. Intent notificationIntent = new Intent(mCtx, DetailActivity.class);
  14.  
  15. notificationIntent.putExtra("url", url);
  16.  
  17. // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
  18. // Intent.FLAG_ACTIVITY_SINGLE_TOP);
  19. notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  20. notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  21. PendingIntent contentIntent = PendingIntent.getActivity(mCtx,
  22. new Random().nextInt(), notificationIntent,
  23. PendingIntent.FLAG_UPDATE_CURRENT);
  24.  
  25. notification = mBuilder.setSmallIcon(R.mipmap.ic_launcher).setTicker(title).setWhen(0)
  26. .setAutoCancel(true)
  27. .setContentIntent(resultPendingIntent)
  28. .setContentTitle(title)
  29. .setSmallIcon(R.mipmap.ic_launcher)
  30. .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
  31. .setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher))
  32. .setContentText(message)
  33. .setSound(soundUri)
  34. .setContentIntent(contentIntent).setAutoCancel(false)
  35. .build();
  36.  
  37. //notification.flags |= Notification.FLAG_AUTO_CANCEL;
  38.  
  39. NotificationManager notificationManager = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
  40. notificationManager.notify(ID_SMALL_NOTIFICATION, notification);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment