【问题标题】:Android Notification Big Picture Style and Big Text StyleAndroid通知大图样式和大文字样式
【发布时间】:2014-08-18 10:48:48
【问题描述】:

我已经使用大图片样式构建了一个推送通知,如 show here。 如附图所示,是否可以混合使用大图片样式和大文本样式?我该怎么做?

【问题讨论】:

标签: android notifications push-notification


【解决方案1】:

你应该可以这样做:

Notification notif = new Notification.Builder(context)
     .setContentTitle("Title")
     .setContentText("content")
     .setSmallIcon(R.drawable.ic_small)
     .setLargeIcon(bitmap)
     .setStyle(new Notification.BigPictureStyle()
         .bigPicture(bigBitmap)
         .setBigContentTitle("big title"))
     .build();

Source

【讨论】:

  • 有没有办法同时获得多行和大图风格?
  • 没有预定义的样式。但是您可以通过远程视图的自定义通知来实现它。
【解决方案2】:

查看更多... 您的通知中的文字是潜台词。 所以在使用 bigpicturestyle 通知时你需要设置

bigPicStyle.setSummaryText(mContent);

mBuilder.setSubText(mSubText);

不能同时设置。

【讨论】:

    【解决方案3】:

    如何创建BigPictureStyle 通知的示例:

     int NOTIFICATION_ID = 1;
        String ns = Context.NOTIFICATION_SERVICE;
    
        //Get the bitmap to show in notification bar
        Bitmap bitmap_image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    
        Bitmap big_bitmap_image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    
    
        NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle()
                .bigPicture(big_bitmap_image)
                .setSummaryText(getResources().getString(R.string.content));
    
        NotificationCompat.Builder nb = new NotificationCompat.Builder(this);
    
                nb.setContentTitle("Notification title"))
                .setContentText("Notification Content")
                .setSmallIcon(R.drawable.ic_launcher)
                .setLargeIcon(bitmap_image)
                .setTicker("Notification ticker!")
                //API Level min 16 is required
                .setStyle(style)
                .build();
    
    
        Intent notificationIntent = new Intent(this, MainActivity2.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    
        TaskStackBuilder TSB = TaskStackBuilder.create(this);
        TSB.addParentStack(MainActivity.class);
    
        TSB.addNextIntent(notificationIntent);
        PendingIntent resultPendingIntent = TSB.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    
        nb.setContentIntent(resultPendingIntent);
        nb.setAutoCancel(true);
        NotificationManager mNotificationManager =
                (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    
        mNotificationManager.notify(NOTIFICATION_ID, nb.build());
    

    这是完整的代码:

    https://github.com/Jorgesys/Android-Notifications

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-12
      • 1970-01-01
      相关资源
      最近更新 更多