3

I am developing a simple android app with custom notifications' layouts. For this purpose I use RemoteViews. I have an ImageView inside my layout but I can't set the bitmap to it.

I use this code to set a bitmap:

layout.setImageViewBitmap(R.id.noteNotificationImage, bitmap)

I also tried to use canvas but that didn't help me:

val proxy = Bitmap.createBitmap(bitmap.width, bitmap.height, Bitmap.Config.ARGB_8888)
                    val c = Canvas(proxy)
                    c.drawBitmap(bitmap, Matrix(), null)
                    layout.setImageViewBitmap(R.id.noteNotificationImage, proxy)

Bitmap is not null and everything works well when I am using it in simple layouts, not in RemoteViews.

Can anyone help me?

Hardik Vasani
  • 876
  • 1
  • 8
  • 14
TopAd Studio
  • 109
  • 6

1 Answers1

-1

I don't konw where is issue, but this code working fine for me

    @SuppressLint("NewApi")
    public void customNotification(String title, String description, String image, Bitmap bitmap) {


        Intent intent = new Intent(mContext,Activity.class);



        long when = System.currentTimeMillis();
        int icon = getNotificationIcon();

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.small_notification);
        RemoteViews expandedView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.big_notification);
        Notification notification = new Notification(icon, getResources().getString(R.string.app_name), when);
        try {
            if (notification != null) {

                notification.contentView = simpleContentView;
                notification.contentIntent = pendingIntent;
                if (currentVersionSupportBigNotification()) {
                    notification.bigContentView = expandedView;
                }
                notification.contentView.setTextViewText(R.id.txt_title_notification, title);
                notification.contentView.setTextViewText(R.id.txt_desc_notification, description);
                if (image != null && !image.equals("")) {
                    try {
                        notification.contentView.setImageViewBitmap(R.id.img_poster_notification, bitmap);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    notification.contentView.setImageViewResource(R.id.img_poster_notification, R.drawable.placeholder_144x214);
                }
                if (currentVersionSupportBigNotification()) {
                    notification.bigContentView.setTextViewText(R.id.txt_title_notification, title);
                    notification.bigContentView.setTextViewText(R.id.txt_desc_notification, description);

                    if (image != null && !image.equals("")) {
                        try {
                            notification.bigContentView.setImageViewBitmap(R.id.img_poster_notification, bitmap);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else {
                        notification.bigContentView.setImageViewResource(R.id.img_poster_notification, R.drawable.placeholder_144x214);
                    }
                }
                notification.flags |= Notification.FLAG_AUTO_CANCEL;
                notification.defaults |= Notification.DEFAULT_LIGHTS;
                notification.defaults |= Notification.DEFAULT_VIBRATE;//Vibration
                notification.defaults |= Notification.DEFAULT_SOUND;
                mNotifyManager = (NotificationManager) getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
                mNotifyManager.notify(NOTIFICATION_ID, notification);
            }
        } catch (Exception e) {
            e.printStackTrace();
            GlobalApp.Log("Notification_exc", "" + e.getMessage());
        }
    }
Hardik Vasani
  • 876
  • 1
  • 8
  • 14