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

The following examples show how to use android.app.TaskStackBuilder#getPendingIntent() . 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: 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 4
Source File: CBIServiceMain.java    From CarBusInterface with MIT License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    if (D) Log.d(TAG, "onCreate()");

    //create this as we need to get user preferences several times
    mSettings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    //setup a receiver to watch for bluetooth adapter state changes
    final IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    this.registerReceiver(mBTStateReceiver, filter);

    //setup the persistent notification as required for any service that returns START_STICKY

    final Intent intent = new Intent(this, CBIActivityMain.class);
    intent.setAction(Intent.ACTION_EDIT);
    final TaskStackBuilder stack = TaskStackBuilder.create(this);
    stack.addParentStack(CBIActivityMain.class);
    stack.addNextIntent(intent);
    PendingIntent resultPendingIntent = stack.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mNoticeBuilder = new Notification.Builder(this);

    mNoticeBuilder.setOngoing(true);
    mNoticeBuilder.setPriority(Notification.PRIORITY_LOW);
    mNoticeBuilder.setContentIntent(resultPendingIntent);
    mNoticeBuilder.setSmallIcon(R.drawable.ic_notice);
    mNoticeBuilder.setContentTitle(getString(R.string.app_name));

    mNoticeStatus = getString(R.string.msg_starting);
    mNoticeBuilder.setContentText(mNoticeStatus);

    mNoticeManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    mNoticeManager.notify(PERSISTENT_NOTIFICATION_ID, mNoticeBuilder.build());
}
 
Example 5
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 6
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 7
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 8
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 9
Source File: AppGcmReceiverUIBackground.java    From RxGcm with Apache License 2.0 5 votes vote down vote up
private PendingIntent getPendingIntentForNotification(Application application, Message message) {
    Class<? extends Activity> classActivity =  message.target().equals(GcmServerService.TARGET_ISSUE_GCM) ? HostActivityIssues.class : HostActivitySupplies.class;

    Intent resultIntent = new Intent(application, classActivity);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(application);
    stackBuilder.addParentStack(classActivity);
    stackBuilder.addNextIntent(resultIntent);

    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_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: 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 12
Source File: BluetoothMedic.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@RequiresApi(21)
private void sendNotification(Context context, String message, String detail) {
    initializeWithContext(context);
    if(this.mNotificationsEnabled) {
        if (!this.mNotificationChannelCreated) {
            createNotificationChannel(context, "err");
        }
        NotificationCompat.Builder builder =
                (new NotificationCompat.Builder(context, "err"))
                        .setContentTitle("BluetoothMedic: " + message)
                        .setSmallIcon(mNotificationIcon)
                        .setVibrate(new long[]{200L, 100L, 200L}).setContentText(detail);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addNextIntent(new Intent("NoOperation"));

        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
                0,
                PendingIntent.FLAG_UPDATE_CURRENT
        );
        builder.setContentIntent(resultPendingIntent);
        NotificationManager notificationManager =
                (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager != null) {
            notificationManager.notify(1, builder.build());
        }
    }
}
 
Example 13
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 14
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 15
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 16
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 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: 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 19
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 20
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();
}