Java Code Examples for android.app.TaskStackBuilder#addNextIntent()

The following examples show how to use android.app.TaskStackBuilder#addNextIntent() . 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: ReminderReceiver.java    From YCNotification with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Log.i(TAG, "ReminderReceiver");
    //Calendar now = GregorianCalendar.getInstance();
    Notification.Builder mBuilder = new Notification.Builder(context)
                    .setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("广播接受者标题,小杨")
                    .setContentText("广播接受者内容,扯犊子")
                    .setAutoCancel(true);

    Log.i(TAG, "onReceive: intent" + intent.getClass().getName());
    Intent resultIntent = new Intent(context, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    //将该Activity添加为栈顶
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    NotificationManager mNotificationManager = (NotificationManager)
            context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, mBuilder.build());
}
 
Example 2
Source File: ForegroundServiceStarter.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private Notification notification() {
    Intent intent = new Intent(mContext, Home.class);
    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(mService);
    b.setOngoing(true);
    b.setCategory(Notification.CATEGORY_SERVICE);
    // Hide this notification "below the fold" on L+
    b.setPriority(Notification.PRIORITY_MIN);
    // Don't show this notification on the lock screen on L+
    b.setVisibility(Notification.VISIBILITY_SECRET);
    b.setContentTitle("xDrip is Running")
            .setContentText("xDrip Data collection service is running.")
            .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on);
    b.setContentIntent(resultPendingIntent);
    return(b.build());
}
 
Example 3
Source File: ITagsService.java    From itag with GNU General Public License v3.0 6 votes vote down vote up
static Notification createForegroundNotification(Context context) {
    createForegroundNotificationChannel(context);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, FOREGROUND_CHANNEL_ID);
    builder
            .setTicker(null)
            .setSmallIcon(R.drawable.app)
            .setContentTitle(context.getString(R.string.service_in_background))
            .setContentText(context.getString(R.string.service_description));
    Intent intent = new Intent(context, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent pendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    builder.setContentIntent(pendingIntent);
    return builder.build();
}
 
Example 4
Source File: NLService.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an intent to open Fit Notifications settings when notification is clicked.
 */
private PendingIntent createSettingsIntent() {
    // Creates an explicit intent for the SettingsActivity in the app
    Intent settingsIntent = new Intent(this, SettingsActivity.class);

    // The stack builder object will contain an artificial back stack for the started Activity.
    // This ensures that navigating backward from the Activity leads out of the application to
    // the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(SettingsActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(settingsIntent);
    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example 5
Source File: DelayedMessageService.java    From HeadFirstAndroid with MIT License 5 votes vote down vote up
private void showText(final String text) {
    // Log.v("DelayedMessageService", "The message is: " + text); // Used in log version
    // handler.post(new Runnable() { // Used in Toast version
    //         @Override
    //         public void run() {
    //             Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG).show();
    //         }
    //     });
    Intent intent = new Intent(this, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent pendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    Notification notification = new Notification.Builder(this)
        .setSmallIcon(R.mipmap.ic_launcher)
        .setContentTitle(getString(R.string.app_name))
        .setAutoCancel(true)
        .setPriority(Notification.PRIORITY_MAX)
        .setDefaults(Notification.DEFAULT_VIBRATE)
        .setContentIntent(pendingIntent)
        .setContentText(text)
        .build();
    NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, notification);
}
 
Example 6
Source File: NotificationReceiver.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 5 votes vote down vote up
private Notification createStreamNotification(StreamInfo stream, @Nullable Bitmap image, boolean showViewers, Context context) {
    Intent resultIntent = LiveStreamActivity.createLiveStreamIntent(stream, false, context);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MyStreamsActivity.class);
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent clickIntent = stackBuilder.getPendingIntent(
            stream.getChannelInfo().getDisplayName().hashCode(),
            PendingIntent.FLAG_UPDATE_CURRENT
    );

    NotificationTextData textData = constructStreamNotificationText(stream, context);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, context.getString(R.string.live_streamer_notification_id))
            .setAutoCancel(false)
            .setContentTitle(textData.getTitle())
            .setContentText(textData.getContent())
            .setGroup(GROUP_KEY)
            .setWhen(stream.getStartedAt())
            .setShowWhen(true)
            .setSmallIcon(R.drawable.ic_notification_icon_refresh)
            .setColor(ContextCompat.getColor(context, R.color.primary))
            .setContentIntent(clickIntent)
            .setSound(null);

    if (image != null) {
        mBuilder.setLargeIcon(image);
    }

    if (showViewers) {
        mBuilder.setSubText(textData.getSubtext());
    }

    return mBuilder.build();
}
 
Example 7
Source File: ComposeTweetService.java    From catnut with MIT License 5 votes vote down vote up
@Override
public void asyncProcess(Context context, JSONObject json) throws Exception {
	// 本地持久化
	ContentValues tweet = Status.METADATA.convert(json);
	tweet.put(Status.TYPE, Status.HOME); // 标记一下
	getContentResolver().insert(CatnutProvider.parse(Status.MULTIPLE), tweet);
	String update = CatnutUtils.increment(true, User.TABLE, User.statuses_count, mApp.getAccessToken().uid);
	getContentResolver().update(CatnutProvider.parse(User.MULTIPLE), null, update, null);
	// 更新status bar
	mBuilder.setContentText(getText(R.string.post_success))
			.setTicker(getText(R.string.post_success))
			.setProgress(0, 0, false);

	// 设置点击后的跳转
	Intent resultIntent = new Intent(ComposeTweetService.this, TweetActivity.class);
	resultIntent.putExtra(Constants.ID, json.optLong(Constants.ID));

	TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(ComposeTweetService.this);
	taskStackBuilder.addParentStack(TweetActivity.class);
	taskStackBuilder.addNextIntent(resultIntent);
	PendingIntent resultPendingIntent =
			taskStackBuilder.getPendingIntent(
					ID,
					PendingIntent.FLAG_UPDATE_CURRENT
			);
	// 判断一下是否是已经保存的草稿
	if (draft.id != Integer.MIN_VALUE) {
		getContentResolver().delete(CatnutProvider.parse(Draft.MULTIPLE), BaseColumns._ID + "=" + draft.id, null);
	}
	mBuilder.setContentIntent(resultPendingIntent);
	mBuilder.setAutoCancel(true);
	mNotifyManager.notify(ID, mBuilder.build());
}
 
Example 8
Source File: RecommendationsService.java    From iview-android-tv with MIT License 5 votes vote down vote up
private PendingIntent buildPendingIntent(EpisodeModel ep) {
    Intent intent = new Intent(this, DetailsActivity.class);
    intent.putExtra(ContentManager.CONTENT_ID, ep);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(DetailsActivity.class);
    stackBuilder.addNextIntent(intent);
    intent.setAction(ep.getHref());

    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example 9
Source File: Notification.java    From BLEMeshChat with Mozilla Public License 2.0 5 votes vote down vote up
private static PendingIntent makePendingIntent(@NonNull Context context, @NonNull Intent resultIntent) {
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    // Gets a PendingIntent containing the entire back stack
    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example 10
Source File: RecommendationsService.java    From iview-android-tv with MIT License 5 votes vote down vote up
private PendingIntent buildPendingIntent(EpisodeModel ep) {
    Intent intent = new Intent(this, DetailsActivity.class);
    intent.putExtra(ContentManager.CONTENT_ID, ep);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(DetailsActivity.class);
    stackBuilder.addNextIntent(intent);
    intent.setAction(ep.getHref());

    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example 11
Source File: RecommendationsService.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
private PendingIntent buildPendingIntent(Video video) {
    Intent detailsIntent = new Intent(this, PlayerActivity.class);
    detailsIntent.putExtra(Video.INTENT_EXTRA_VIDEO, video);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(VideoDetailsActivity.class);
    stackBuilder.addNextIntent(detailsIntent);
    // Ensure a unique PendingIntents, otherwise all recommendations end up with the same
    // PendingIntent
    detailsIntent.setAction(Long.toString(video.getId()));

    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example 12
Source File: UpdateRecommendationsService.java    From BuildingForAndroidTV with MIT License 5 votes vote down vote up
private PendingIntent buildPendingIntent(Movie movie, int id) {
    Intent detailsIntent = new Intent(this, MovieDetailsActivity.class);
    detailsIntent.putExtra(MovieDetailsActivity.MOVIE, movie);
    detailsIntent.putExtra(MovieDetailsActivity.NOTIFICATION_ID, id);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MovieDetailsActivity.class);
    stackBuilder.addNextIntent(detailsIntent);
    // Ensure a unique PendingIntents, otherwise all recommendations end up with the same
    // PendingIntent
    detailsIntent.setAction(movie.getId());

    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example 13
Source File: UpdateService.java    From FacebookNotifications with MIT License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private Notification.Builder getNewStyleNotification(int smallIcon, Bitmap largeIcon, String title, String text, int priority, Intent resultIntent, int notifType, String soundURI, long[] vibrationPattern) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = getString(R.string.R_string_notif_channel_name);
        String description = getString(R.string.notif_channel_description);
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
        channel.setDescription(description);
        // Register the channel with the system; you can't change the importance
        // or other notification behaviors after this
        NotificationManager notificationManager = getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(channel);
    }

    Notification.Builder mBuilder =
            new Notification.Builder(getApplicationContext())
                    .setSmallIcon(smallIcon)
                    .setLargeIcon(largeIcon)
                    .setContentTitle(title)
                    .setContentText(text)
                    .setPriority(priority)
                    .setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        mBuilder.setChannelId(CHANNEL_ID);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder.setCategory(Notification.CATEGORY_SOCIAL)
                .setVisibility(Notification.VISIBILITY_PRIVATE);
    }

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    if (soundURI != null) {
        Uri uri = Uri.parse(soundURI);
        mBuilder.setSound(uri);
    }

    mBuilder.setVibrate(vibrationPattern);

    return mBuilder;
}
 
Example 14
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 15
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 16
Source File: Notifier.java    From batteryhub with Apache License 2.0 4 votes vote down vote up
public static void remainingBatteryTimeAlert(final Context context,
                                             String timeRemaining, boolean charging) {
    String text = !charging ? "Battery remaining time" : "Remaining time until full charge";

    sBuilder = new NotificationCompat.Builder(context, "remaining_battery_time")
            .setContentTitle(timeRemaining)
            .setContentText(text)
            .setAutoCancel(false)
            .setOngoing(true)
            .setPriority(SettingsUtils.fetchNotificationsPriority(context));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        sBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    if (!charging) {
        sBuilder.setSmallIcon(R.drawable.ic_battery_50_grey600_24dp);
    } else {
        sBuilder.setSmallIcon(R.drawable.ic_battery_50_white_24dp);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.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
            );
    sBuilder.setContentIntent(resultPendingIntent);
    sNotificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    sNotificationManager.notify(Config.NOTIFICATION_BATTERY_STATUS, sBuilder.build());
    isStatusBarShown = true;
}
 
Example 17
Source File: Notifier.java    From batteryhub with Apache License 2.0 4 votes vote down vote up
public static void startStatusBar(final Context context) {
    if (isStatusBarShown) return;

    // At this moment Inspector still doesn't have a current level assigned
    DataEstimator estimator = new DataEstimator();
    estimator.getCurrentStatus(context);

    double now = Battery.getBatteryCurrentNow(context);
    int level = estimator.getLevel();
    String title = context.getString(R.string.now) + ": " + now + " mA";
    String text = context.getString(R.string.notif_batteryhub_running);

    sBuilder = new NotificationCompat.Builder(context, "start_status")
            .setContentTitle(title)
            .setContentText(text)
            .setAutoCancel(false)
            .setOngoing(true)
            .setPriority(SettingsUtils.fetchNotificationsPriority(context));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        sBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    if (level < 100) {
        sBuilder.setSmallIcon(R.drawable.ic_stat_00_pct_charged + level);
    } else {
        sBuilder.setSmallIcon(R.drawable.ic_stat_z100_pct_charged);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.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
            );
    sBuilder.setContentIntent(resultPendingIntent);
    sNotificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    sNotificationManager.notify(Config.NOTIFICATION_BATTERY_STATUS, sBuilder.build());
    isStatusBarShown = true;
}
 
Example 18
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 19
Source File: PApp.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
public Notification create(Map map) {

            Bitmap iconBmp = null;
            String iconName = (String) map.get("icon");
            if (iconName != null)
                iconBmp = BitmapFactory.decodeFile(getAppRunner().getProject().getFullPathForFile(iconName));

            String launchOnClick = null;
            launchOnClick = (String) map.get("launchOnClick");
            Project p = new Project(launchOnClick);

            String notificationData = null;
            notificationData = (String) map.get("notificationData");
            this.id = ((Number) map.get("id")).intValue();

            Intent intent = new Intent(getContext(), MyBroadcastReceiver.class);
            intent.putExtra("notificationData", notificationData);
            intent.putExtra(Project.FOLDER, p.getFolder());
            intent.putExtra(Project.NAME, p.getName());
            intent.putExtra("isNotification", true);
            intent.putExtra("notificationId", this.id);

            PendingIntent deletePendingIntent = PendingIntent.getBroadcast(getContext(), 0, intent, 0);

            // Creates an explicit intent for an Activity in your app
            Intent resultIntent = new Intent(getContext(), AppRunnerActivity.class);
            resultIntent.putExtra("notificationData", notificationData);
            resultIntent.putExtra(Project.FOLDER, p.getFolder());
            resultIntent.putExtra(Project.NAME, p.getName());
            resultIntent.putExtra("isNotification", true);
            resultIntent.putExtra("notificationId", this.id);

            // The stack builder object will contain an artificial back stack for navigating backward from the Activity leads out your application to the Home screen.
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(getContext());
            stackBuilder.addParentStack(AppRunnerActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

            this.mBuilder = new NotificationCompat.Builder(getContext(), getAppRunner().getProject().name)
                    .setSmallIcon(R.drawable.bubble)
                    .setContentTitle((CharSequence) map.get("title"))
                    .setContentText((CharSequence) map.get("description"))
                    .setLights(Color.parseColor((String) map.get("color")), 1000, 1000)
                    .setLargeIcon(iconBmp)
                    .setAutoCancel((Boolean) map.get("autocancel"))
                    .setTicker((String) map.get("ticker"))
                    .setSubText((CharSequence) map.get("subtext"))
                    .setDeleteIntent(deletePendingIntent)
                    .setContentIntent(resultPendingIntent);

            // damm annoying android pofkjpodsjf0ewiah
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                int importance = NotificationManager.IMPORTANCE_LOW;
                NotificationChannel mChannel = new NotificationChannel(getAppRunner().getProject().name, getAppRunner().getProject().name, importance);
                // mChannel.setDescription("lalalla");
                mChannel.enableLights(false);
                mNotificationManager.createNotificationChannel(mChannel);
            } else {
            }

            return this;
        }
 
Example 20
Source File: BaseActivity.java    From secure-quick-reliable-login with MIT License 4 votes vote down vote up
public void showClearNotification() {
    final String CHANNEL_ID = "sqrl_notify_01";

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, "SQRL Notification Channel", NotificationManager.IMPORTANCE_DEFAULT);
        notificationChannel.enableVibration(false);
        notificationChannel.enableLights(false);
        notificationChannel.setSound(null, null);

        if (notificationManager != null) {
            notificationManager.createNotificationChannel(notificationChannel);
        }
    }

    long[] v = {};
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this, CHANNEL_ID)
                    .setSmallIcon(R.drawable.ic_sqrl_logo_vector_outline)
                    .setContentTitle(getString(R.string.notification_identity_unlocked))
                    .setContentText(getString(R.string.notification_identity_unlocked_title))
                    .setAutoCancel(true)
                    .setVibrate(v)
                    .setSound(null)
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(getString(R.string.notification_identity_unlocked_desc)));

    Intent intentClearQuickpass = new Intent(this, ClearQuickPassActivity.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            .addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
            .addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
            .setAction(ClearQuickPassActivity.ACTION_CLEAR_QUICK_PASS);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(intentClearQuickpass);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    mBuilder.setContentIntent(resultPendingIntent);

    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (mNotificationManager != null) {
        mNotificationManager.notify(NOTIFICATION_IDENTITY_UNLOCKED, mBuilder.build());
    }
}