Search in sources :

Example 1 with BigPictureStyle

use of android.support.v4.app.NotificationCompat.BigPictureStyle in project RSAndroidApp by RailwayStations.

the class NearbyBahnhofWithPhotoNotificationManager method onBitmapAvailable.

/**
     * This gets called if the requested bitmap is available. Finish and issue the notification.
     *
     * @param bitmap the fetched Bitmap for the notification. May be null
     */
@Override
public void onBitmapAvailable(@Nullable Bitmap bitmap) {
    if (context == null) {
        // we're already destroyed
        return;
    }
    if (bitmap == null) {
        bitmap = getBitmapFromResource(R.drawable.ic_stations_with_photo);
    }
    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
    if (fetchTask != null) {
        bigPictureStyle.bigPicture(bitmap).setBigContentTitle(null).setSummaryText(fetchTask.getLicense());
    }
    Notification fullImagePage = new NotificationCompat.Builder(context).setStyle(bigPictureStyle).extend(new NotificationCompat.WearableExtender().setHintShowBackgroundOnly(true).setHintScreenTimeout(NotificationCompat.WearableExtender.SCREEN_TIMEOUT_LONG)).build();
    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().setHintHideIcon(true).setBackground(bitmap).addPage(fullImagePage);
    NotificationCompat.Builder notificationBuilder = getBasicNotificationBuilder();
    // apply our specifics
    notificationBuilder.extend(wearableExtender).setVibrate(VIBRATION_PATTERN).setColor(LED_COLOR);
    // ...and we're done!
    onNotificationReady(notificationBuilder.build());
}
Also used : NotificationCompat(android.support.v4.app.NotificationCompat) Notification(android.app.Notification)

Example 2 with BigPictureStyle

use of android.support.v4.app.NotificationCompat.BigPictureStyle in project AgileDev by LZ9.

the class NotificationUtils method notificationBuild.

/**
 * 如何创建一个Notification
 */
private void notificationBuild(Context context, Bitmap bitmap, @DrawableRes int drawableId, @LayoutRes int layoutId) {
    // 获取构造器,channelId在O(26)才有用可以随便传
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "123456");
    // ---------------------- 常用 ---------------------
    // 在5.0以上不显示Ticker属性信息
    builder.setTicker("状态栏显示的提示");
    // 通知栏通知的标题
    builder.setContentTitle("内容标题");
    // 通知栏通知的详细内容(只有一行)
    builder.setContentText("内容文本信息");
    // 设置为true,点击该条通知会自动删除,false时只能通过滑动来删除(一般都是true)
    builder.setAutoCancel(true);
    // 通知上面的小图标(必传)
    builder.setSmallIcon(drawableId);
    // ---------------------- 不常用 ---------------------
    // 通知消息上的大图标(可传可不传)
    builder.setLargeIcon(bitmap);
    // 这边设置颜色,可以给5.0及以上版本smallIcon设置背景色(基本不使用)
    builder.setColor(Color.RED);
    // 设置该条通知时间(基本不使用)
    builder.setWhen(System.currentTimeMillis());
    // 设置是否为一个正在进行中的通知,这一类型的通知将无法删除(基本不使用)
    builder.setOngoing(false);
    // ---------------------- 设置意图 ---------------------
    PendingIntent pIntent = PendingIntent.getActivity(context, 1, new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.baidu.com")), // 创建一个意图
    PendingIntent.FLAG_ONE_SHOT);
    // 将意图设置到通知上
    builder.setContentIntent(pIntent);
    // 横幅通知(有的系统会直接打开PendingIntent)推荐使用setContentIntent()
    builder.setFullScreenIntent(pIntent, true);
    // ---------------------- 提示音和优先级 ---------------------
    // NotificationCompat.DEFAULT_SOUND/NotificationCompat.DEFAULT_VIBRATE/NotificationCompat.DEFAULT_LIGHTS
    // 通知默认的声音 震动 呼吸灯
    builder.setDefaults(NotificationCompat.DEFAULT_ALL);
    // NOTIFI_PRIORITY_MAX, NOTIFI_PRIORITY_HIGH, NOTIFI_PRIORITY_DEFAULT, NOTIFI_PRIORITY_LOW, NOTIFI_PRIORITY_MIN
    // 设置优先级,级别高的排在前面
    builder.setPriority(NotificationCompat.PRIORITY_MAX);
    // ---------------------- 进度条 ---------------------
    // 设置进度条setProgress(0, 0, false)为移除进度条
    builder.setProgress(100, 10, true);
    // ---------------------- 设置大文本样式 ---------------------
    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    // 给样式设置大文本的标题
    bigTextStyle.setBigContentTitle("大文本的标题");
    // 给样式设置大文本内容
    bigTextStyle.bigText("这里是点击通知后要显示的正文,正文很多字正文很多字正文很多字");
    // 总结,可以不设置
    bigTextStyle.setSummaryText("末尾只一行的文字内容");
    // 将样式添加到通知
    builder.setStyle(bigTextStyle);
    // ---------------------- 多行大文本样式 ---------------------
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    // 给样式设置大文本的标题
    inboxStyle.setBigContentTitle("大文本的标题");
    // 设置每行内容
    inboxStyle.addLine("啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦");
    inboxStyle.addLine("哈哈哈哈哈");
    inboxStyle.addLine("嘻嘻嘻嘻");
    // 总结,可以不设置
    inboxStyle.setSummaryText("末尾只一行的文字内容");
    builder.setStyle(inboxStyle);
    // ---------------------- 大图文本样式 ---------------------
    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
    // 给样式设置大文本的标题
    bigPictureStyle.setBigContentTitle("大文本的标题");
    // 大文本的内容(只有一行)
    bigPictureStyle.setSummaryText("末尾只一行的文字内容");
    // 设置大图
    bigPictureStyle.bigPicture(bitmap);
    builder.setStyle(bigPictureStyle);
    // ---------------------- 自定义内容样式 ---------------------
    // 模拟layout里面的资源id
    int R_id_title = 1;
    // 模拟layout里面的资源id
    int R_id_img = 2;
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), layoutId);
    // 设置对应id的内容
    remoteViews.setTextViewText(R_id_title, "自定义文本");
    remoteViews.setImageViewResource(R_id_img, drawableId);
    builder.setContent(remoteViews);
    // 构建通知
    Notification notification = builder.build();
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) RemoteViews(android.widget.RemoteViews) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 3 with BigPictureStyle

use of android.support.v4.app.NotificationCompat.BigPictureStyle in project Pix-Art-Messenger by kriztan.

the class NotificationService method modifyForImage.

private void modifyForImage(final Builder builder, final UnreadConversation.Builder uBuilder, final Message message, final ArrayList<Message> messages) {
    try {
        final Bitmap bitmap = mXmppConnectionService.getFileBackend().getThumbnail(message, getPixel(288), false);
        final ArrayList<Message> tmp = new ArrayList<>();
        for (final Message msg : messages) {
            if (msg.getType() == Message.TYPE_TEXT && msg.getTransferable() == null) {
                tmp.add(msg);
            }
        }
        final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
        bigPictureStyle.bigPicture(bitmap);
        if (tmp.size() > 0) {
            CharSequence text = getMergedBodies(tmp);
            bigPictureStyle.setSummaryText(text);
            builder.setContentText(text);
        } else {
            builder.setContentText(mXmppConnectionService.getString(R.string.received_x_file, UIHelper.getFileDescriptionString(mXmppConnectionService, message)));
        }
        builder.setStyle(bigPictureStyle);
    } catch (final FileNotFoundException e) {
        modifyForTextOnly(builder, uBuilder, messages);
    }
}
Also used : Bitmap(android.graphics.Bitmap) Message(de.pixart.messenger.entities.Message) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) BigPictureStyle(android.support.v4.app.NotificationCompat.BigPictureStyle)

Example 4 with BigPictureStyle

use of android.support.v4.app.NotificationCompat.BigPictureStyle in project AgileDev by LZ9.

the class NotificationActivity method showLargeImgNotify.

/**
 * 大图文本样式
 */
private void showLargeImgNotify() {
    // 获取构造器
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext(), NOTIFI_CHANNEL_MAIN_ID);
    // 通知栏显示的文字
    builder.setTicker("阿森纳の梗");
    // 通知栏通知的标题
    builder.setContentTitle("阿森纳与4的不解之缘");
    // 通知栏通知的详细内容(只有一行)
    builder.setContentText("争4狂魔,没4找4");
    // 设置为true,点击该条通知会自动删除,false时只能通过滑动来删除(一般都是true)
    builder.setAutoCancel(true);
    // 通知上面的小图标(必传)
    builder.setSmallIcon(R.mipmap.ic_launcher);
    // 通知默认的声音 震动 呼吸灯
    builder.setDefaults(NotificationCompat.DEFAULT_ALL);
    // 设置优先级,级别高的排在前面
    builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
    // 给样式设置大文本的标题
    bigPictureStyle.setBigContentTitle("温格的无奈");
    // 大文本的内容(只有一行)
    bigPictureStyle.setSummaryText("忠义法 纳私利 范雄心 宋公明");
    // 设置大图
    bigPictureStyle.bigPicture(BitmapFactory.decodeResource(getResources(), R.drawable.ic_regret));
    builder.setStyle(bigPictureStyle);
    // 构建通知
    Notification notification = builder.build();
    NotificationUtils.create(getContext()).send(notification);
}
Also used : NotificationCompat(android.support.v4.app.NotificationCompat) Notification(android.app.Notification)

Example 5 with BigPictureStyle

use of android.support.v4.app.NotificationCompat.BigPictureStyle in project AprilBeacon-Android-SDK by AprilBrother.

the class NotifyService method setBigPictureStyleNotification.

/**
 * Big Picture Style Notification
 *
 * @return Notification
 * @see CreateNotification
 */
private Notification setBigPictureStyleNotification(String content) {
    Bitmap remote_picture = null;
    // Create the style object with BigPictureStyle subclass.
    NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();
    notiStyle.setBigContentTitle("Big Picture Expanded");
    notiStyle.setSummaryText("Nice big picture.");
    try {
        remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent());
    } catch (IOException e) {
        e.printStackTrace();
    }
    // Add the big picture to the style.
    notiStyle.bigPicture(remote_picture);
    // Creates an explicit intent for an ResultActivity to receive.
    Intent resultIntent = new Intent(this, ResultActivity.class);
    // This ensures that the back button follows the recommended convention
    // for the back key.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself).
    stackBuilder.addParentStack(ResultActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack.
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    return new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setLargeIcon(remote_picture).setContentIntent(resultPendingIntent).addAction(R.drawable.ic_launcher, "One", resultPendingIntent).addAction(R.drawable.ic_launcher, "Two", resultPendingIntent).addAction(R.drawable.ic_launcher, "Three", resultPendingIntent).setContentTitle("Big Picture Normal").setContentText(content).setStyle(notiStyle).build();
}
Also used : Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) IOException(java.io.IOException) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) URL(java.net.URL)

Aggregations

NotificationCompat (android.support.v4.app.NotificationCompat)5 Notification (android.app.Notification)3 PendingIntent (android.app.PendingIntent)3 Intent (android.content.Intent)3 Bitmap (android.graphics.Bitmap)3 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 BigPictureStyle (android.support.v4.app.NotificationCompat.BigPictureStyle)1 RemoteViews (android.widget.RemoteViews)1 Message (de.pixart.messenger.entities.Message)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1