push notification not working with NotificationCompat.BigPictureStyle (couldn't inflate view for notification)

0

I am trying to display big picture image in the notification tray. Here is the code

Intent resultIntent = new Intent(mCtx, PostsActivity.class);
        resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        resultIntent.putExtra("notificationId", data.get("id"));
        PendingIntent pendingIntent = PendingIntent.getActivity(mCtx, 0, resultIntent, PendingIntent.FLAG_ONE_SHOT);
 Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Bitmap bitmap = getBitmapfromUrl
                (data.get("image"));
        String title = data.get("title");
        String body = data.get("body");
        //Bitmap picture = BitmapFactory.decodeResource(bitmap);
        final NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(mCtx, Constants.CHANNEL_ID)
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentTitle(title)
                        .setContentText(body)
                        .setAutoCancel(true)
                        .setSound(soundUri)
                        .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap))
                        .setContentIntent(pendingIntent);

                NotificationManager mNotifyMgr =
                        (NotificationManager) ctx.getSystemService(NOTIFICATION_SERVICE);

                if (mNotifyMgr != null) {
                    mNotifyMgr.notify(0, mBuilder.build());
                } 


 public Bitmap getBitmapfromUrl(String imageUrl) {
        try {
            URL url = new URL(imageUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            return BitmapFactory.decodeStream(input);

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

AndroidMenifest.xml

<service
        android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

Logcat error when applying the code for BigPictureStyle.

    07-28 23:02:38.157 1728-1728/? E/StatusBar: couldn't inflate view for notification com.notification.app/0x0
    android.widget.RemoteViews$ActionException: view: android.widget.FrameLayout doesn't have method: setEmphasizedMode(boolean)
        at android.widget.RemoteViews.getMethod(RemoteViews.java:851)
        at android.widget.RemoteViews.-wrap5(RemoteViews.java)
        at android.widget.RemoteViews$ReflectionAction.apply(RemoteViews.java:1411)
        at android.widget.RemoteViews.performApply(RemoteViews.java:3425)
        at android.widget.RemoteViews.apply(RemoteViews.java:3160)
        at com.android.systemui.statusbar.BaseStatusBar.inflateViews(BaseStatusBar.java:603)
        at com.android.systemui.statusbar.BaseStatusBar.addNotificationViews(BaseStatusBar.java:972)
        at com.android.systemui.statusbar.phone.PhoneStatusBar.addNotification(PhoneStatusBar.java:1940)
        at com.android.systemui.statusbar.CommandQueue$H.handleMessage(CommandQueue.java:442)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6184)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:788)
07-28 23:02:38.158 1728-1728/? E/StatusBar: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.notification.app user=UserHandle{0} id=0 tag=null key=0|com.notification.app|0|null|10464: Notification(pri=0 contentView=null vibrate=null sound=content://settings/system/notification_sound defaults=0x0 flags=0x10 color=0x00000000 actions=1 vis=PRIVATE))

I am able to receive the notification without NotificationCompat.BigPictureStyle(). But when I use new NotificationCompat.BigPictureStyle(), I don't receive notification. I searched all over the internet but nothing helped me. I don't know what's going wrong.

Please help!

android
push-notification
android-notifications
asked on Stack Overflow Jul 22, 2018 by user2970035 • edited Jul 28, 2018 by user2970035

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0