Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static final int ID_BIG_NOTIFICATION = 234;
- public static final int ID_SMALL_NOTIFICATION = 235;
- private Context mCtx;
- public MyNotificationManager(Context mCtx) {
- this.mCtx = mCtx;
- }
- //the method will show a big notification with an image
- //parameters are title for message title, message for message text, url of the big image and an intent that will open
- //when you will tap on the notification
- public void showBigNotification(String title, String message, String url, Intent intent) {
- PendingIntent resultPendingIntent =
- PendingIntent.getActivity(
- mCtx,
- ID_BIG_NOTIFICATION,
- intent,
- PendingIntent.FLAG_UPDATE_CURRENT
- );
- Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
- NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
- bigPictureStyle.setBigContentTitle(title);
- bigPictureStyle.setSummaryText(Html.fromHtml(message));
- bigPictureStyle.bigPicture(getBitmapFromURL(url));
- // try {
- // bigPictureStyle.bigPicture(Picasso.with(mCtx).load(url).networkPolicy(NetworkPolicy.NO_CACHE).memoryPolicy(MemoryPolicy.NO_CACHE).skipMemoryCache().get());
- // } catch (IOException e) {
- // e.printStackTrace();
- // }
- NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx);
- Notification notification;
- Intent notificationIntent = new Intent(mCtx, NotificationActivity.class);
- notificationIntent.putExtra("title",title);
- notificationIntent.putExtra("message", message);
- notificationIntent.putExtra("image", url);
- // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
- // Intent.FLAG_ACTIVITY_SINGLE_TOP);
- notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- PendingIntent contentIntent = PendingIntent.getActivity(mCtx,
- new Random().nextInt(), notificationIntent,
- PendingIntent.FLAG_UPDATE_CURRENT);
- notification = mBuilder.setSmallIcon(R.mipmap.ic_launcher).setTicker(title).setWhen(0)
- .setAutoCancel(true)
- .setContentIntent(resultPendingIntent)
- .setContentTitle(title)
- .setStyle(bigPictureStyle)
- .setPriority(Notification.PRIORITY_MAX)
- .setSmallIcon(R.mipmap.ic_launcher)
- .setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher))
- .setContentText(message)
- .setSound(alarmSound)
- .setContentIntent(contentIntent).setAutoCancel(true)
- .build();
- //notification.flags |= Notification.FLAG_AUTO_CANCEL;
- NotificationManager notificationManager = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
- notificationManager.notify(ID_BIG_NOTIFICATION, notification);
- }
Advertisement
Add Comment
Please, Sign In to add comment