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

The following examples show how to use android.app.TaskStackBuilder#addParentStack() . 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: 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 2
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 3
Source File: PassiveService.java    From privacy-friendly-netmonitor with GNU General Public License v3.0 6 votes vote down vote up
private void showAppNotification() {
    mBuilder.setSmallIcon(R.drawable.ic_notification);
    mBuilder.setLargeIcon(mIcon);
    Intent resultIntent = new Intent(this, 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(this);

    // 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);
    mBuilder.setContentIntent(resultPendingIntent);

    startForeground(SERVICE_IDENTIFIER, mBuilder.build());
}
 
Example 4
Source File: ComposeTweetService.java    From catnut with MIT License 6 votes vote down vote up
private void fallback(Draft draft, String error) {
	draft.createAt = System.currentTimeMillis();
	getContentResolver().insert(CatnutProvider.parse(Draft.MULTIPLE), Draft.METADATA.convert(draft));
	mBuilder.setContentTitle(getString(R.string.post_fail))
			.setContentText(error)
			.setTicker(getText(R.string.post_fail))
			.setProgress(0, 0, false);

	// 添加fallback跳转
	Intent resultIntent = SingleFragmentActivity.getIntent(this, SingleFragmentActivity.DRAFT);

	TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this);
	taskStackBuilder.addParentStack(SingleFragmentActivity.class);
	taskStackBuilder.addNextIntent(resultIntent);
	PendingIntent resultPendingIntent =
			taskStackBuilder.getPendingIntent(
					ID,
					PendingIntent.FLAG_UPDATE_CURRENT
			);
	mBuilder.setContentIntent(resultPendingIntent)
			.setAutoCancel(true);
	mNotifyManager.notify(ID, mBuilder.build());
}
 
Example 5
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 6
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 7
Source File: WakeupReceiver.java    From loaned-android with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
private void doNotification(Context c, Person person, Item item, Loan loan){
	// Get picture for person. If none available, use app icon
	// Calculate days on loan
	// Set title to item name
	// Set message to "{person name} has had this for {number of days} days"
	// Set Intent to open app to main screen
	NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c);
	mBuilder.setSmallIcon(R.drawable.ic_launcher_grey);
	mBuilder.setContentTitle(item.getName());
	long timeDifference = new Date().getTime()-loan.getStartDate().getTime();
	int days = (int) (timeDifference / (1000*60*60*24));
	mBuilder.setContentText(person.getName()+" has had this item for "+ Integer.toString(days) +" days");
	NotificationManager mNotificationManager = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
	Intent resultIntent = new Intent(c, LoanHistoryActivity.class);
	Bundle b = new Bundle();
	// Set which fragment to show based on the user's preference of preferred view
	if(SettingsFragment.isShowingItemList(c)){
		b.putBoolean(LoanHistoryActivity.IS_FOR_ITEM, true);
		b.putInt(LoanHistoryActivity.ITEM_ID, item.getItemID());
	} else {
		b.putBoolean(LoanHistoryActivity.IS_FOR_ITEM, false);
		b.putInt(LoanHistoryActivity.PERSON_ID, person.getPersonID());
	}
	resultIntent.putExtras(b);
	// 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.
	if(Build.VERSION.SDK_INT>=16){ // If JellyBean or newer
		TaskStackBuilder stackBuilder = TaskStackBuilder.create(c);
		// Adds the back stack for the Intent (but not the Intent itself)
		stackBuilder.addParentStack(MainActivity.class);
		stackBuilder.addNextIntent(resultIntent);
		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
				PendingIntent.FLAG_UPDATE_CURRENT);
		mBuilder.setContentIntent(resultPendingIntent);
	}
	// NOTIFICATION_ID allows you to update the notification later on.
	mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
 
Example 8
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 9
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 10
Source File: PassiveService.java    From privacy-friendly-netmonitor with GNU General Public License v3.0 5 votes vote down vote up
private void showWarningNotification() {
    //Set corresponding icon
    //if(Evidence.getMaxSeverity() > 2){
    //    mBuilder.setSmallIcon(R.mipmap.icon_warn_red);
    //    mBuilder.setLargeIcon(mWarnRed);
    //} else {
    //    mBuilder.setSmallIcon(R.mipmap.icon_warn_orange);
    //    mBuilder.setLargeIcon(mWarnOrange);
    //}
    //mBuilder.setContentText(mNotificationCount + " new warnings encountered.");

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

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // 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);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    // mId allows you to update the notification later on.
    mNotificationManager.notify(Const.LOG_TAG, 1, mBuilder.build());
}
 
Example 11
Source File: BleManager.java    From thunderboard-android with Apache License 2.0 5 votes vote down vote up
private void sendNotification(Beacon beacon) {

        // check if notifications are enabled and allowed for the beacon
        if (!BleUtils.checkAllowNotifications(beacon.getBluetoothAddress(), preferenceManager.getPreferences())) {
            Timber.d("Notifications not allowed for : %s, address: %s", beacon.getBluetoothName(), beacon.getBluetoothAddress());
            return;
        }

        NotificationCompat.Builder builder =
                new NotificationCompat.Builder(context)
                        .setContentTitle(context.getResources().getString(R.string.app_name))
                        .setContentText(String.format("%s is nearby.", beacon.getBluetoothName()))
                        .setSmallIcon(R.drawable.ic_stat_sl_beacon)
                        .setAutoCancel(true);


        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

        Intent intent = new Intent(context, DemosSelectionActivity.class);
        intent.putExtra(ThunderBoardConstants.EXTRA_DEVICE_BEACON, (Parcelable) beacon);
        stackBuilder.addParentStack(DemosSelectionActivity.class);
        stackBuilder.addNextIntent(intent);

        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(resultPendingIntent);
        NotificationManager notificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(beacon.getId3().toInt(), builder.build());
    }
 
Example 12
Source File: RecommendationsService.java    From Amphitheatre with Apache License 2.0 5 votes vote down vote up
private PendingIntent buildPendingIntent(Video video) {
    Intent detailsIntent = new Intent(this, DetailsActivity.class);
    detailsIntent.putExtra(Constants.VIDEO, video);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(DetailsActivity.class);
    stackBuilder.addNextIntent(detailsIntent);
    detailsIntent.setAction(Long.toString(video.getId()));

    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example 13
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 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: 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 18
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 19
Source File: AppRunnerService.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
private void createNotification(final int notificationId, String scriptFolder, String scriptName) {
    IntentFilter filter = new IntentFilter();
    filter.addAction(SERVICE_CLOSE);

    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(SERVICE_CLOSE)) {
                AppRunnerService.this.stopSelf();
                mNotifManager.cancel(notificationId);
            }
        }
    };

    registerReceiver(mReceiver, filter);

    //RemoteViews remoteViews = new RemoteViews(getPackageName(),
    //        R.layout.widget);

    Intent stopIntent = new Intent(SERVICE_CLOSE);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.phonk_icon)
            .setContentTitle(scriptName).setContentText("Running service: " + scriptFolder + " > " + scriptName)
            .setOngoing(false)
            .addAction(R.drawable.phonk_icon, "stop", pendingIntent)
            .setDeleteIntent(pendingIntent);

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

    // 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(this);
    stackBuilder.addParentStack(AppRunnerActivity.class);
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);
    mNotificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
    mNotificationManager.notify(notificationId, mBuilder.build());
    Thread.setDefaultUncaughtExceptionHandler(handler);

}
 
Example 20
Source File: NotificationReceiver.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 4 votes vote down vote up
private void createStreamSummaryNotification(Bitmap largeIcon, NotificationFetchData notificationData, NotificationManager manager, Context context) {
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MyStreamsActivity.class);
    stackBuilder.addNextIntent(new Intent(context, MyStreamsActivity.class));
    PendingIntent clickIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationTextData notificationText = constructMainNotificationText(notificationData, context);
    if (notificationText.getTitle().isEmpty() || notificationText.getContent().isEmpty()) {
        return;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, context.getString(R.string.live_streamer_notification_id))
            .setAutoCancel(true)
            .setContentTitle(notificationText.getTitle())
            .setContentText(notificationText.getContent())
            .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationText.getContent()))
            .setGroup(GROUP_KEY)
            .setGroupSummary(true)
            .setContentIntent(clickIntent)
            .setSubText(notificationText.getSubtext())
            .setLargeIcon(largeIcon)
            .setSmallIcon(R.drawable.ic_notification_icon_refresh)
            .setColor(ContextCompat.getColor(context, R.color.primary));

    Settings settings = new Settings(context);
    boolean toVibrate = settings.getNotificationsVibrations();
    boolean toWakeScreen = settings.getNotificationsScreenWake();
    boolean toPlaySound = settings.getNotificationsSound();
    boolean toBlinkLED = settings.getNotificationsLED();
    boolean isQuietHoursEnabled = settings.getNotificationsQuietHours();
    boolean isInQuietHours = isQuietHoursEnabled && isInQuietTime(settings);

    if(toWakeScreen && !isInQuietHours) {
        PowerManager.WakeLock screenOn = null;
        PowerManager powerManager = ((PowerManager) context.getSystemService(Context.POWER_SERVICE));
        if (powerManager != null) {
            screenOn = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "pocketplays:lock");
        }
        if (screenOn != null) {
            screenOn.acquire(2000);
        }
    }

    if(toVibrate && !isInQuietHours) {
        // Set the notification to vibrate
        final int DELAY = 0;
        final int VIBRATE_DURATION = 100;
        mBuilder.setVibrate(new long[] {
                DELAY,
                VIBRATE_DURATION,
                0,
                0
        });
    }
    if(toPlaySound && !isInQuietHours)
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    if(toBlinkLED && !isInQuietHours)
        mBuilder.setLights(Color.BLUE, 5000, 5000);

    manager.notify(NOTIFICATION_ID, mBuilder.build());
}