Android/자료정리
[android]GCM, Notification, 이미지 추가하기. ( BigPictureStyle )
썩소천사
2015. 4. 23. 16:38
반응형
GCM관련하여 Notification을 생성할 때 이미지를 보여줄 수 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | try { URL url = new URL("https://xxx.com/test.jpg"); URLConnection conn = url.openConnection(); conn.connect(); BufferedInputStream bis = new BufferedInputStream( conn.getInputStream()); Bitmap imgBitmap = BitmapFactory.decodeStream(bis); bis.close(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setTicker(title) .setContentTitle(title) .setVibrate(new long[]{200,200,200,200}) .setContentText(message) .setPriority(Notification.PRIORITY_MAX) .setAutoCancel(true); NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle(); style.setBigContentTitle(title); style.setSummaryText(message); style.bigPicture(imgBitmap); mBuilder.setStyle(style); mBuilder.setContentIntent(contentIntent); mBuilder.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.sound)); NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notiId, mBuilder.build()); } catch (Exception e) { // TODO: handle exception } | cs |
이미지가 잘 나오지 않을경우 bitmap이 생성되었는지 로그를 통해 확인하고,
Notification.PRIORITY_MAX 부분의 옵션이 다른 (PRIORITY_HIGH) 옵션등으로 설정되었는지 확인해 보기 바란다.
반응형