Not able to get user's profile picture of Whatsapp from mobile Notification using NotificationListnerService

Viewed 42

Hi I am trying to get user's profile photo of WhatsApp from NotificationListnerService, But it gives ClassCastException error if I am casing EXTRA_LARGE_ICON with bitmap. So is it possible to get large icon from notification ?

String ticker ="";
        if(sbn.getNotification().tickerText !=null) {
            ticker = sbn.getNotification().tickerText.toString();
        }
        Bundle extras = sbn.getNotification().extras;
        String title = extras.getString("android.title");
        String text = extras.getCharSequence("android.text").toString();
        int id1 = extras.getInt(Notification.EXTRA_SMALL_ICON);
        //Bitmap id = sbn.getNotification().largeIcon;
        Bitmap id = (Bitmap) extras.get(Notification.EXTRA_LARGE_ICON);



        Intent msgrcv = new Intent("Msg");
        msgrcv.putExtra("package", pack);
        msgrcv.putExtra("ticker", ticker);
        msgrcv.putExtra("title", title);
        msgrcv.putExtra("text", text);
        if(id != null) {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            id.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] byteArray = stream.toByteArray();
            msgrcv.putExtra("icon",byteArray);
        }
        LocalBroadcastManager.getInstance(context).sendBroadcast(msgrcv);

If I used sbn.getNotification().largeIcon I will get large icon in below OS 10, but In OS 11 and 12 it returns null.

0 Answers
Related