当前位置: 首页>>代码示例>>Java>>正文


Java Notification.BigPictureStyle方法代码示例

本文整理汇总了Java中android.app.Notification.BigPictureStyle方法的典型用法代码示例。如果您正苦于以下问题:Java Notification.BigPictureStyle方法的具体用法?Java Notification.BigPictureStyle怎么用?Java Notification.BigPictureStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.Notification的用法示例。


在下文中一共展示了Notification.BigPictureStyle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: build

import android.app.Notification; //导入方法依赖的package包/类
@Override
public Notification build() {
    // Note: this is not a NotificationCompat builder so be mindful of the
    // API level of methods you call on the builder.
    Notification.Builder builder = new Notification.Builder(mContext);
    builder.setContentTitle(mTitle);
    builder.setContentText(mBody);
    builder.setSubText(mOrigin);
    builder.setTicker(mTickerText);
    if (mImage != null) {
        Notification.BigPictureStyle style =
                new Notification.BigPictureStyle().bigPicture(mImage);
        if (Build.VERSION.CODENAME.equals("N")
                || Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
            // Android N doesn't show content text when expanded, so duplicate body text as a
            // summary for the big picture.
            style.setSummaryText(mBody);
        }
        builder.setStyle(style);
    } else {
        // If there is no image, let the body text wrap only multiple lines when expanded.
        builder.setStyle(new Notification.BigTextStyle().bigText(mBody));
    }
    builder.setLargeIcon(getNormalizedLargeIcon());
    setSmallIconOnBuilder(builder, mSmallIconId, mSmallIconBitmap);
    builder.setContentIntent(mContentIntent);
    builder.setDeleteIntent(mDeleteIntent);
    for (Action action : mActions) {
        addActionToBuilder(builder, action);
    }
    if (mSettingsAction != null) {
        addActionToBuilder(builder, mSettingsAction);
    }
    builder.setDefaults(mDefaults);
    builder.setVibrate(mVibratePattern);
    builder.setWhen(mTimestamp);
    builder.setOnlyAlertOnce(!mRenotify);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Notification.Builder.setPublicVersion was added in Android L.
        builder.setPublicVersion(createPublicNotification(mContext));
    }
    return builder.build();
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:44,代码来源:StandardNotificationBuilder.java

示例2: getNotificationBuilder

import android.app.Notification; //导入方法依赖的package包/类
/**
 * Gets Notification.Builder with 2 lines at BigPictureStyle notification text.
 *
 * @param context The application context.
 * @param message Push notification Bundle.
 * @param contentIntent PendingIntent.
 * @param title String with title for push notification.
 * @param messageText String with text for push notification.
 * @param bigPicture Bitmap for BigPictureStyle notification.
 * @param defaultNotificationIconResourceId int Resource id for default push notification icon.
 * @return Notification.Builder or null.
 */
static Notification.Builder getNotificationBuilder(Context context, Bundle message,
    PendingIntent contentIntent, String title, final String messageText, Bitmap bigPicture,
    int defaultNotificationIconResourceId) {
  if (Build.VERSION.SDK_INT < 16) {
    return null;
  }
  Notification.Builder notificationBuilder =
      getNotificationBuilder(context, message);
  if (defaultNotificationIconResourceId == 0) {
    notificationBuilder.setSmallIcon(context.getApplicationInfo().icon);
  } else {
    notificationBuilder.setSmallIcon(defaultNotificationIconResourceId);
  }
  notificationBuilder.setContentTitle(title)
      .setContentText(messageText);
  Notification.BigPictureStyle bigPictureStyle = new Notification.BigPictureStyle() {
    @Override
    protected RemoteViews getStandardView(int layoutId) {
      RemoteViews remoteViews = super.getStandardView(layoutId);
      // Modifications of stanxdard push RemoteView.
      try {
        int id = Resources.getSystem().getIdentifier("text", "id", "android");
        remoteViews.setBoolean(id, "setSingleLine", false);
        remoteViews.setInt(id, "setLines", 2);
        if (Build.VERSION.SDK_INT < 23) {
          // Make text smaller.
          remoteViews.setViewPadding(id, 0, BIGPICTURE_TEXT_TOP_PADDING, 0, 0);
          remoteViews.setTextViewTextSize(id, TypedValue.COMPLEX_UNIT_SP, BIGPICTURE_TEXT_SIZE);
        }
      } catch (Throwable throwable) {
        Log.e("Cannot modify push notification layout.");
      }
      return remoteViews;
    }
  };

  bigPictureStyle.bigPicture(bigPicture)
      .setBigContentTitle(title)
      .setSummaryText(message.getString(Constants.Keys.PUSH_MESSAGE_TEXT));
  notificationBuilder.setStyle(bigPictureStyle);

  if (Build.VERSION.SDK_INT >= 24) {
    // By default we cannot reach getStandardView method on API>=24. I we call
    // createBigContentView, Android will call getStandardView method and we can get
    // modified RemoteView.
    try {
      RemoteViews remoteView = notificationBuilder.createBigContentView();
      if (remoteView != null) {
        // We need to set received RemoteView as a custom big content view.
        notificationBuilder.setCustomBigContentView(remoteView);
      }
    } catch (Throwable t) {
      Log.e("Cannot modify push notification layout.", t);
    }
  }

  notificationBuilder.setAutoCancel(true);
  notificationBuilder.setContentIntent(contentIntent);
  return notificationBuilder;
}
 
开发者ID:Leanplum,项目名称:Leanplum-Android-SDK,代码行数:73,代码来源:LeanplumNotificationHelper.java


注:本文中的android.app.Notification.BigPictureStyle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。