3

I successfully modify big picture notification using such code

static class MyMultiLineBigPictureStyle extends Notification.BigPictureStyle{
    @NonNull
    @Override
    protected RemoteViews getStandardView(int layoutId) {
        RemoteViews ret =  super.getStandardView(layoutId);
        int id =  Resources.getSystem().getIdentifier("text", "id", "android");
        ret.setBoolean(id, "setSingleLine", false);
        ret.setInt(id, "setLines", 4);
        return ret;
    }
}

This works well on API < 24. On API 24,25 and 26 this method isn't even called. Can't see explanation for it

Enuviel
  • 316
  • 2
  • 7
  • Why don't you just move the code of handling the BigPictureStyle into the notifcation handling area instead of relying on overriding the BigPictureStyle callbacks? – Sam Oct 04 '17 at 05:19
  • You mean via NotificationBuilder (there is no "lines" setting available there) or custom layout.xml? With custom layout notification looks different comparing to system-native notification. I don't see simple way to support all of these differences with custom layout. – Enuviel Oct 04 '17 at 05:31

2 Answers2

1

After you overridden getStandardView - you cannot reach this method on API>=24. But if you call createBigContentView, Android will call getStandardView method and you can get modified RemoteView. And then you need to set received RemoteView as a custom big content view.

   if (Build.VERSION.SDK_INT >= 24) {
    try {
      RemoteViews remoteView = notificationBuilder.createBigContentView();
      if (remoteView != null) {
        notificationBuilder.setCustomBigContentView(remoteView);
      }
    } catch (Throwable t) {
      Log.e("","Cannot modify push notification layout.");
    }
  }
Enuviel
  • 316
  • 2
  • 7
-1

Ok as I can't post this in my comment to you so posting it here as answer.

public class SendNotificationAsyncTask extends AsyncTask<String, Void, Bitmap> {

    /*///////////////////////////////////////////////////////////////
    // MEMBERS
    *////////////////////////////////////////////////////////////////
    private static final String TAG = Globals.SEARCH_STRING + SendNotificationAsyncTask.class.getSimpleName();
    private Context mContext;
    private String mMessage;
    private String mImageUrl;
    private String mIdOfDetailToShow;


    /*///////////////////////////////////////////////////////////////
    // CONSTRUCTOR
    *////////////////////////////////////////////////////////////////
    public SendNotificationAsyncTask(Context context, String imageUrl, String message, String idToShow) {
        super();
        mContext = context;
        mMessage = message;
        mImageUrl = imageUrl;
        mIdOfDetailToShow = idToShow;

    }


    /*///////////////////////////////////////////////////////////////
    // BASECLASS OVERRIDES
    *////////////////////////////////////////////////////////////////
    @Override
    protected Bitmap doInBackground(String... params) {
        InputStream in;
        try {
            URL url = new URL(mImageUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setConnectTimeout(10000);
            connection.setReadTimeout(10000);
            connection.setDoInput(true);
            connection.setInstanceFollowRedirects(true);
            connection.connect();
            in = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(in);

            return myBitmap;

        } catch (MalformedURLException e) {
            A35Log.e(TAG, e.getMessage());

        } catch (IOException e) {
            A35Log.e(TAG, e.getMessage());

        }

        return null;

    }
    @Override
    protected void onPostExecute(Bitmap result) {
        super.onPostExecute(result);

        try {
            NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

            Intent intent = new Intent(mContext, SplashScreenActivity.class);
            intent.putExtra(Globals.INTENT_KEYS.KEY_FROM_BADGE_ACCESS, true);
            intent.putExtra(Globals.INTENT_KEYS.KEY_ID_OF_DETAIL_TO_OPEN, mIdOfDetailToShow);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);

            Notification notification = new Notification.Builder(mContext)
                    .setContentTitle(mContext.getResources().getString(R.string.app_name))
                    .setContentText(mMessage)
                    .setSmallIcon(R.drawable.logo_main_white)
                    .setContentIntent(pendingIntent)
                    .setStyle(new Notification.BigPictureStyle().bigPicture(result))
                    .setLargeIcon(result).build();

            // hide the notification after its selected
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            notificationManager.notify(1, notification);

        } catch (Exception e) {
            A35Log.e(TAG, e.getMessage());

        }

    }

}

I basically download the image and then create the large image notification. I have not had any issues in 25 or 26 and it is confirmed tested.

Sam
  • 5,342
  • 1
  • 23
  • 39
  • Ok, and how would force it to show two or more lines of text in summary like this: https://stackoverflow.com/questions/28043878/android-big-picture-style-notification-with-multi-line-summary-text – Enuviel Oct 04 '17 at 05:39
  • I have not actually tried to do that. I have not had a need to do two lines yet but once you figure it out, please share back your solution – Sam Oct 04 '17 at 20:09
  • a hacky way would be to include the text inside the image and create one single image from the downloaded bitmap and the text you want to display. It's not perfect, but you can certainly do it. – Sam Oct 04 '17 at 20:10