tegarkurniawan

bigPicture

Feb 15th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. public void showBigNotification(String title, String message, String url, Intent intent) {
  2. PendingIntent resultPendingIntent =
  3. PendingIntent.getActivity(
  4. mCtx,
  5. ID_BIG_NOTIFICATION,
  6. intent,
  7. PendingIntent.FLAG_UPDATE_CURRENT
  8. );
  9. Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  10. NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
  11. bigPictureStyle.setBigContentTitle(title);
  12. bigPictureStyle.setSummaryText(Html.fromHtml(message));
  13. bigPictureStyle.bigPicture(getBitmapFromURL(url));
  14. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx);
  15. Notification notification;
  16. Intent notificationIntent = new Intent(mCtx, NotificationActivity.class);
  17.  
  18. notificationIntent.putExtra("title",title);
  19. notificationIntent.putExtra("message", message);
  20. notificationIntent.putExtra("image", url);
  21.  
  22. // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
  23. // Intent.FLAG_ACTIVITY_SINGLE_TOP);
  24. notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  25. notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  26. PendingIntent contentIntent = PendingIntent.getActivity(mCtx,
  27. new Random().nextInt(), notificationIntent,
  28. PendingIntent.FLAG_UPDATE_CURRENT);
  29. notification = mBuilder.setSmallIcon(R.mipmap.ic_launcher).setTicker(title).setWhen(0)
  30. .setAutoCancel(true)
  31. .setContentIntent(resultPendingIntent)
  32. .setContentTitle(title)
  33. .setStyle(bigPictureStyle)
  34. .setPriority(Notification.PRIORITY_MAX)
  35. .setSmallIcon(R.mipmap.ic_launcher)
  36. .setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher))
  37. .setContentText(message)
  38. .setSound(alarmSound)
  39. .setContentIntent(contentIntent).setAutoCancel(true)
  40. .build();
  41.  
  42.  
  43. //notification.flags |= Notification.FLAG_AUTO_CANCEL;
  44.  
  45. NotificationManager notificationManager = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
  46. notificationManager.notify(ID_BIG_NOTIFICATION, notification);
  47. }
  48. private Bitmap getBitmapFromURL(String strURL) {
  49. try {
  50. URL url = new URL(strURL);
  51. HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  52. connection.setDoInput(true);
  53. connection.connect();
  54. InputStream input = connection.getInputStream();
  55. Bitmap myBitmap = BitmapFactory.decodeStream(input);
  56. return myBitmap;
  57. } catch (IOException e) {
  58. e.printStackTrace();
  59. return null;
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment