How to apply a big view style to a notification using Parse library

前端 未结 8 875
孤街浪徒
孤街浪徒 2021-02-04 06:03

This library works perfectly, but i have a doubt.

When I send a message to users with more than two lines, users can\'t see all message in notification area.

But

8条回答
  •  暖寄归人
    2021-02-04 06:46

    Here I have attached a screenshots, the first screen contents a title of the post and when we click on the down arrow on right side of the app name it leads to the second screenshot which is custom layout for push notification.The following is sample layout that I have designed for mine.

    
    
    
    
    
    
    
     
     
    
    

    Method for creating Notification with custom layout,

    public static void createNotification(String title, String body,String image_url, Context context, int notificationsId, String single_id) {
    Intent notificationIntent;
    
    long when = System.currentTimeMillis();
    int id = (int) System.currentTimeMillis();
    
    Bitmap bitmap = getBitmapFromURL(image_url);
    NotificationCompat.BigPictureStyle notifystyle = new NotificationCompat.BigPictureStyle();
    notifystyle.bigPicture(bitmap);
    RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.custom_notification_layout);
    contentView.setImageViewBitmap(R.id.image, bitmap);
    contentView.setTextViewText(R.id.title, body);
    
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher)
            .setStyle(notifystyle)
            .setCustomBigContentView(contentView)
            .setContentText(body);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    
    notificationIntent = new Intent(context, SinglePost.class);
    notificationIntent.putExtra("single_id",single_id);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(context, id, notificationIntent, 0); 
    
    Notification notification = mBuilder.build();
    notification.contentIntent = contentIntent;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    
    
    mNotificationManager.notify(notificationsId, notification);
    
    }
    
    public static Bitmap getBitmapFromURL(String strURL) {
    try {
        URL url = new URL(strURL);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        return myBitmap;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    }
    

提交回复
热议问题