Java Code Examples for android.support.v4.app.NotificationCompat#BigPictureStyle

The following examples show how to use android.support.v4.app.NotificationCompat#BigPictureStyle . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotificationUtils.java    From LNMOnlineAndroidSample with Apache License 2.0 6 votes vote down vote up
private void showBigNotification(Bitmap bitmap, NotificationCompat.Builder mBuilder, int icon, String title, String message, String timeStamp, PendingIntent resultPendingIntent, Uri alarmSound) {
    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
    bigPictureStyle.setBigContentTitle(title);
    bigPictureStyle.setSummaryText(Html.fromHtml(message).toString());
    bigPictureStyle.bigPicture(bitmap);
    Notification notification;
    notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent)
            .setSound(alarmSound)
            .setStyle(bigPictureStyle)
            .setWhen(getTimeMilliSec(timeStamp))
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
            .setContentText(message)
            .build();

    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID_BIG_IMAGE, notification);
}
 
Example 2
Source File: NotificationUtils.java    From protrip with MIT License 6 votes vote down vote up
private void showBigNotification(Bitmap bitmap, NotificationCompat.Builder mBuilder, int icon, String title, String message, String timeStamp, PendingIntent resultPendingIntent, Uri alarmSound) {
    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
    bigPictureStyle.setBigContentTitle(title);
    bigPictureStyle.setSummaryText(Html.fromHtml(message).toString());
    bigPictureStyle.bigPicture(bitmap);
    Notification notification;
    notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent)
            .setSound(alarmSound)
            .setStyle(bigPictureStyle)
            .setWhen(getTimeMilliSec(timeStamp))
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
            .setContentText(message)
            .build();

    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Constants.NOTIFICATION_ID_BIG_IMAGE, notification);
}
 
Example 3
Source File: MainActivity.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
public void sendBig(View view) {
    //1.创建Builder
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.mipmap.hmv).setTicker("大图标通知");
    //2.创建BigPictureStyle
    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle(builder);
    //3.设置BigPictureStyle
    //标题
    bigPictureStyle.setSummaryText("大图标内容文本")
            .setBigContentTitle("大图标标题");
    //设置大图片,bitmap对象
    //把R.drawable.id-->Bitmap
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.big);
    bigPictureStyle.bigPicture(bitmap);
    //4.发送
    Notification notification = builder.build();

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(103, notification);


}
 
Example 4
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle();
    style.bigPicture(BitmapFactory.decodeResource(context.getResources(),
            R.drawable.example_big_picture));
    style.setBigContentTitle(context.getString(R.string.big_picture_style_example_title));
    style.setSummaryText(context.getString(
            R.string.big_picture_style_example_summary_text));

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setStyle(style);
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender();
    applyBasicOptions(context, builder, wearableOptions, options);
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example 5
Source File: FollowingCheckService.java    From droidddle with Apache License 2.0 5 votes vote down vote up
private Notification getNotification(Shot shot, boolean sound) {
    int notificationId = shot.id.intValue();
    // Build intent for notification content
    Intent viewIntent = new Intent(this, MainActivity.class);
    viewIntent.setAction(UiUtils.ACTION_OPEN_SHOT);
    viewIntent.putExtra(UiUtils.ARG_ID, shot.id.longValue());
    viewIntent.putExtra(UiUtils.ARG_SHOT, shot);
    PendingIntent viewPendingIntent = PendingIntent
            .getActivity(this, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    String ticker = shot.title + " by " + shot.user.name;
    long when = System.currentTimeMillis();//shot.createdAt == null ? System.currentTimeMillis() : shot.createdAt.getTime();
    Bitmap shotImage = getShotImage(shot);
    Bitmap avatar = getUserAvatar(shot);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_shot).setContentTitle(shot.title)
            .setContentText(getDescription(shot)).setAutoCancel(true).setCategory(
                    NotificationCompat.CATEGORY_SOCIAL)
            //.setContentInfo(shot.user.name)
            .setContentIntent(viewPendingIntent).setGroup(GROUP_KEY).setShowWhen(true)
            .setWhen(when).setTicker(ticker).setColor(COLOR).setLights(COLOR, 400, 5600)
            .setSubText(shot.user.name);
    if (sound && !isMuteTime()) {
        notificationBuilder.setDefaults(NotificationCompat.DEFAULT_SOUND);
    }
    if (avatar != null) {
        notificationBuilder.setLargeIcon(avatar);
    }

    if (shotImage != null) {
        NotificationCompat.BigPictureStyle pictureStyle = new NotificationCompat.BigPictureStyle();
        pictureStyle.bigPicture(shotImage).setBigContentTitle(shot.title);
        //.setSummaryText(getDescriptioin(shot));
        notificationBuilder.setStyle(pictureStyle);
    }
    return notificationBuilder.build();
}
 
Example 6
Source File: BigPictureStyleConverter.java    From json2notification with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(NotificationCompat.BigPictureStyle bigPictureStyle, String fieldName, boolean writeFieldNameForObject,
        JsonGenerator jsonGenerator) throws IOException {
    android.util.Log.d("json2notification", "BigPictureStyleConverter:serialize");
    if (bigPictureStyle == null) return;
    SimpleBigPictureStyle simpleBigPictureStyle = new SimpleBigPictureStyle();
    // TODO
    if (writeFieldNameForObject) jsonGenerator.writeFieldName(fieldName);
    new SimpleBigPictureStyle$$JsonObjectMapper().serialize((SimpleBigPictureStyle) simpleBigPictureStyle, jsonGenerator, true);
}
 
Example 7
Source File: NotificationUtil.java    From MyBlogDemo with Apache License 2.0 5 votes vote down vote up
/**
     * 发送一个点击跳转到MainActivity的消息
     */
    public static void sendSimplestNotificationWithAction(Context context) {

        NotificationManager mNotifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        //获取PendingIntent
        Intent mainIntent = new Intent(context, MainActivity.class);
        PendingIntent mainPendingIntent = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        //创建 Notification.Builder 对象
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.mipmap.ic_launcher)
//                .setTicker("啦啦啦啦啦啦啦啦啦啦啦啦阿拉啦啦啦啦啦啦啦啦啦",)
                //点击通知后自动清除
                .setAutoCancel(true)
                .setContentTitle("我是tittle")
                .setContentText("我是内容")
                .setNumber(++number)
                .setPriority(2)
                .setContentIntent(mainPendingIntent);
        NotificationCompat.InboxStyle inboxStyle =
                new NotificationCompat.InboxStyle();

        String[] events = new String[]{"CCCCCCCCCCCCCCCCC","DDDDDDDDDDDDDDDDDDDDD","EEEEEEEEEEEEEEEEEEEE","FFFFFFFFFFFFFFFFFFFF","HHHHHHHHHHHHHHHHHHH",};
// Sets a title for the Inbox in expanded layout
        inboxStyle.setBigContentTitle("Event tracker details:");
// Moves events into the expanded layout
        for (int i = 0; i < events.length; i++) {
            inboxStyle.addLine(events[i]);
        }

        NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
//        bigPictureStyle.bigPicture(BitmapFactory.decodeResource(context.getResources(), R.mipmap.about_bg));
        bigPictureStyle.setSummaryText("啦啦啦啦啦啦啦啦啦DDDDDDDDDDDDDDDDDDDDD啦啦啦啦啦啦啦");
// Moves the expanded layout object into the notification object.
//        builder.setStyle(bigPictureStyle);

        //发送通知
        mNotifyManager.notify(3, builder.build());
    }
 
Example 8
Source File: NotificationService.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
private void displayNotification() {
	Log.d(TAG, "displayNotification");

	RecipesRecord record = SQuery.newQuery().selectFirst(Recipes.CONTENT_URI, "random()");

	Bitmap image = ImageLoader.getInstance().loadImageSync(record.getImage());

	Log.d(TAG, String.format("chosen %s for notification", record.getId()));

	Intent intent = RecipeItemListActivity.newIntentForRecipe(this, record.getId())
			.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
	NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
			.setAutoCancel(true)
			.setSmallIcon(R.drawable.ic_launcher)
			.setPriority(NotificationCompat.PRIORITY_LOW)
			.setLargeIcon(image)
			.setDeleteIntent(
					PendingIntent.getService(this, 0, getIntentForDelete(this),
							PendingIntent.FLAG_UPDATE_CURRENT))
			.setContentIntent(
					PendingIntent.getActivity(this, 0, intent,
							PendingIntent.FLAG_UPDATE_CURRENT))
			.setContentTitle(record.getName());

	NotificationCompat.BigPictureStyle bigStyle = new NotificationCompat.BigPictureStyle()
			.bigLargeIcon(
					((BitmapDrawable) getResources().getDrawable(R.drawable.ic_launcher))
							.getBitmap()).bigPicture(image);

	// Moves the big view style object into the notification object.
	builder.setStyle(bigStyle);

	// mId allows you to update the notification later on.
	Log.d(TAG, "displaying notification");
	notificationManager.notify(1, builder.build());

	EasyTracker.getInstance(this).send(
			MapBuilder.createEvent("notification", "display", "recipe notification", 1l)
					.build());
}
 
Example 9
Source File: NotificationService.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private void modifyForImage(final Builder builder, 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);
            builder.setTicker(text);
        } else {
            final String description = UIHelper.getFileDescriptionString(mXmppConnectionService, message);
            builder.setContentText(description);
            builder.setTicker(description);
        }
        builder.setStyle(bigPictureStyle);
    } catch (final IOException e) {
        modifyForTextOnly(builder, messages);
    }
}
 
Example 10
Source File: NotifyUtil.java    From NotificationDemo with Apache License 2.0 4 votes vote down vote up
public static NotificationCompat.BigPictureStyle makeBigPicture(Bitmap bitmap) {
    return new NotificationCompat.BigPictureStyle().bigPicture(bitmap);
}
 
Example 11
Source File: Notifications.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public Notification createOngoingNotification(Context context) {
    mContext = context;
    long end = System.currentTimeMillis() + (60000 * 5);
    long start = end - (60000 * 60*3) -  (60000 * 10);
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(mContext, start, end);
    ReadPerfs(mContext);
    Intent intent = new Intent(mContext, Home.class);
    List<BgReading> lastReadings = BgReading.latest(2);
    BgReading lastReading = null;
    if (lastReadings != null && lastReadings.size() >= 2) {
        lastReading = lastReadings.get(0);
    }

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    stackBuilder.addParentStack(Home.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );

    NotificationCompat.Builder b = new NotificationCompat.Builder(mContext);
    //b.setOngoing(true);
    b.setCategory(NotificationCompat.CATEGORY_STATUS);
    String titleString = lastReading == null ? "BG Reading Unavailable" : (lastReading.displayValue(mContext) + " " + lastReading.slopeArrow());
    b.setContentTitle(titleString)
            .setContentText("xDrip Data collection service is running.")
            .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on)
            .setUsesChronometer(false);
    if (lastReading != null) {
        b.setWhen(lastReading.timestamp);
        String deltaString = "Delta: " + bgGraphBuilder.unitizedDeltaString(true, true);
        b.setContentText(deltaString);
        iconBitmap = new BgSparklineBuilder(mContext)
                .setHeight(64)
                .setWidth(64)
                .setStart(System.currentTimeMillis() - 60000 * 60 * 3)
                .setBgGraphBuilder(bgGraphBuilder)
                .build();
        b.setLargeIcon(iconBitmap);
        NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
        notifiationBitmap = new BgSparklineBuilder(mContext)
                .setBgGraphBuilder(bgGraphBuilder)
                .showHighLine()
                .showLowLine()
                .build();
        bigPictureStyle.bigPicture(notifiationBitmap)
                .setSummaryText(deltaString)
                .setBigContentTitle(titleString);
        b.setStyle(bigPictureStyle);
    }
    b.setContentIntent(resultPendingIntent);
    return b.build();
}
 
Example 12
Source File: Notifications.java    From NightWatch with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public Notification createOngoingNotification(BgGraphBuilder bgGraphBuilder, Context context) {
    mContext = context;
    ReadPerfs(mContext);
    Intent intent = new Intent(mContext, Home.class);
    List<Bg> lastReadings = Bg.latest(2);
    Bg lastReading = null;
    if (lastReadings != null && lastReadings.size() >= 2) {
        lastReading = lastReadings.get(0);
    }

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    stackBuilder.addParentStack(Home.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );

    NotificationCompat.Builder b = new NotificationCompat.Builder(mContext);
    //b.setOngoing(true);
    b.setCategory(NotificationCompat.CATEGORY_STATUS);
    String titleString = lastReading == null ? "BG Reading Unavailable" : (lastReading.displayValue(mContext) + " " + lastReading.slopeArrow());
    b.setContentTitle(titleString)
            .setContentText("xDrip Data collection service is running.")
            .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on)
            .setUsesChronometer(false);
    if (lastReading != null) {
        b.setWhen((long)lastReading.datetime);
        String deltaString = "Delta: " + bgGraphBuilder.unitizedDeltaString(true, true);
        b.setContentText(deltaString);
        iconBitmap = new BgSparklineBuilder(mContext)
                .setHeight(64)
                .setWidth(64)
                .setStart(System.currentTimeMillis() - 60000 * 60 * 3)
                .setBgGraphBuilder(bgGraphBuilder)
                .build();
        b.setLargeIcon(iconBitmap);
        NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
        notifiationBitmap = new BgSparklineBuilder(mContext)
                .setBgGraphBuilder(bgGraphBuilder)
                .showHighLine()
                .showLowLine()
                .build();
        bigPictureStyle.bigPicture(notifiationBitmap)
                .setSummaryText(deltaString)
                .setBigContentTitle(titleString);
        b.setStyle(bigPictureStyle);
    }
    b.setContentIntent(resultPendingIntent);
    return b.build();
}
 
Example 13
Source File: Notifications.java    From NightWatch with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public Notification createOngoingNotification(BgGraphBuilder bgGraphBuilder, Context context) {
    mContext = context;
    ReadPerfs(mContext);
    Intent intent = new Intent(mContext, Home.class);
    List<Bg> lastReadings = Bg.latest(2);
    Bg lastReading = null;
    if (lastReadings != null && lastReadings.size() >= 2) {
        lastReading = lastReadings.get(0);
    }

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    stackBuilder.addParentStack(Home.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );

    NotificationCompat.Builder b = new NotificationCompat.Builder(mContext);
    //b.setOngoing(true);
    b.setCategory(NotificationCompat.CATEGORY_STATUS);
    String titleString = lastReading == null ? "BG Reading Unavailable" : (lastReading.displayValue(mContext) + " " + lastReading.slopeArrow());
    b.setContentTitle(titleString)
            .setContentText("xDrip Data collection service is running.")
            .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on)
            .setUsesChronometer(false);
    if (lastReading != null) {
        b.setWhen((long)lastReading.datetime);
        String deltaString = "Delta: " + bgGraphBuilder.unitizedDeltaString(true, true);
        b.setContentText(deltaString);
        iconBitmap = new BgSparklineBuilder(mContext)
                .setHeight(64)
                .setWidth(64)
                .setStart(System.currentTimeMillis() - 60000 * 60 * 3)
                .setBgGraphBuilder(bgGraphBuilder)
                .build();
        b.setLargeIcon(iconBitmap);
        NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
        notifiationBitmap = new BgSparklineBuilder(mContext)
                .setBgGraphBuilder(bgGraphBuilder)
                .showHighLine()
                .showLowLine()
                .build();
        bigPictureStyle.bigPicture(notifiationBitmap)
                .setSummaryText(deltaString)
                .setBigContentTitle(titleString);
        b.setStyle(bigPictureStyle);
    }
    b.setContentIntent(resultPendingIntent);
    return b.build();
}
 
Example 14
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 4 votes vote down vote up
private void buildNotification() {
	NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
	if ( !TextUtils.isEmpty(mNotificationTitleEditText.getText() ) ) {
		builder.setContentTitle(mNotificationTitleEditText.getText());
	} else {
		builder.setContentTitle(getString(R.string.app_name));
	}
	if( !TextUtils.isEmpty( mNotificationTextEditText.getText() ) ) {
		builder.setContentText(mNotificationTextEditText.getText());
	} else {
		builder.setContentText( getString(R.string.app_name) );
	}
	builder.setSmallIcon( R.drawable.ic_launcher );

	if( !TextUtils.isEmpty( mNotificationInfoEditText.getText() ) )
		builder.setContentInfo( mNotificationInfoEditText.getText() );

	if( !TextUtils.isEmpty( mNotificationSubEditText.getText() ) )
		builder.setSubText(mNotificationSubEditText.getText());

	if( !TextUtils.isEmpty( mNotificationTickerEditText.getText() ) )
		builder.setTicker(mNotificationTickerEditText.getText());

	if( mNotificationLargeCheckBox.isChecked() )
		builder.setLargeIcon(BitmapFactory.decodeResource( this.getResources(), R.drawable.ic_launcher ) );

	if( mNotificationSoundCheckBox.isChecked() )
		builder.setSound( RingtoneManager.getDefaultUri( RingtoneManager.TYPE_NOTIFICATION ) );

	if( mNotificationShowChronometerCheckBox.isChecked() )
		builder.setUsesChronometer( true );

	if( mNotificationVibrationCheckBox.isChecked() )
		builder.setVibrate( new long[]{ 0, 500, 250, 500 } );

	if( mNotificationUseIntent.isChecked() ) {
		Intent intent = new Intent( this, MainActivity.class );
		TaskStackBuilder stackBuilder = TaskStackBuilder.create( this );
		stackBuilder.addNextIntent( intent );
		PendingIntent resultIntent =  stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
		builder.setContentIntent( resultIntent );
		builder.setAutoCancel( true );
	}

	if( mNotificationBigPictureStyleCheckBox.isChecked() ) {
		NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle();
		style.bigPicture(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher));
		builder.setStyle(style);
	}

	NotificationManager manager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE );
	manager.notify( 1, builder.build() );
}