Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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));
- 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);
- }
- private Bitmap getBitmapFromURL(String strURL) {
- try {
- URL url = new URL(strURL);
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- connection.setDoInput(true);
- connection.connect();
- InputStream input = connection.getInputStream();
- Bitmap myBitmap = BitmapFactory.decodeStream(input);
- return myBitmap;
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment