android.app.TaskStackBuilder Java Examples

The following examples show how to use android.app.TaskStackBuilder. 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: StageService.java    From AndroidSamples with Apache License 2.0 7 votes vote down vote up
private void showNotification() {
    // 创建通知栏
    Notification.Builder mBuilder = new Notification.Builder(this)
            .setSmallIcon(R.drawable.img_tm)
            .setContentTitle("标题")
            .setContentText("文本");
    // 点击跳转到Activity
    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);
    // 设置跳转
    mBuilder.setContentIntent(pendingIntent);

    // 获取通知服务
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // 构建通知
    Notification notification = mBuilder.build();
    // 显示通知
    nm.notify(0,notification);

    // 启动前台服务
    startForeground(0,notification);
}
 
Example #2
Source File: TwoShortcutActivitiesGenerated.java    From shortbread with Apache License 2.0 6 votes vote down vote up
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, SimpleShortcutActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(SimpleShortcutActivity.class)
                    .addNextIntent(new Intent(context, SimpleShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID_2")
            .setShortLabel("SHORT_LABEL")
            .setLongLabel("LONG_LABEL")
            .setIcon(Icon.createWithResource(context, 123))
            .setDisabledMessage("DISABLED_MESSAGE")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(AdvancedShortcutActivity.class)
                    .addNextIntent(new Intent(context, AdvancedShortcutActivity.class)
                            .setAction("ACTION"))
                    .getIntents())
            .setRank(1)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
Example #3
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 #4
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 #5
Source File: BeaconReferenceApplication.java    From android-beacon-library-reference with Apache License 2.0 6 votes vote down vote up
private void sendNotification() {
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(this)
                    .setContentTitle("Beacon Reference Application")
                    .setContentText("An beacon is nearby.")
                    .setSmallIcon(R.drawable.ic_launcher);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addNextIntent(new Intent(this, MonitoringActivity.class));
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager =
            (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, builder.build());
}
 
Example #6
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 #7
Source File: TwoMethodShortcutsActivityGenerated.java    From shortbread with Apache License 2.0 6 votes vote down vote up
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, TwoMethodShortcutsActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(TwoMethodShortcutsActivity.class)
                    .addNextIntent(new Intent(context, TwoMethodShortcutsActivity.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod1"))
                    .getIntents())
            .setRank(0)
            .build());
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID_2")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, TwoMethodShortcutsActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(TwoMethodShortcutsActivity.class)
                    .addNextIntent(new Intent(context, TwoMethodShortcutsActivity.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod2"))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
Example #8
Source File: TwoMethodShortcutActivitiesGenerated.java    From shortbread with Apache License 2.0 6 votes vote down vote up
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, MethodShortcutActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(MethodShortcutActivity.class)
                    .addNextIntent(new Intent(context, MethodShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod"))
                    .getIntents())
            .setRank(0)
            .build());
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, MethodShortcutActivity2.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(MethodShortcutActivity2.class)
                    .addNextIntent(new Intent(context, MethodShortcutActivity2.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod"))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
Example #9
Source File: AdvancedShortcutActivityGenerated.java    From shortbread with Apache License 2.0 6 votes vote down vote up
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID_2")
            .setShortLabel("SHORT_LABEL")
            .setLongLabel("LONG_LABEL")
            .setIcon(Icon.createWithResource(context, 123))
            .setDisabledMessage("DISABLED_MESSAGE")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(AdvancedShortcutActivity.class)
                    .addNextIntent(new Intent(context, AdvancedShortcutActivity.class)
                            .setAction("ACTION"))
                    .getIntents())
            .setRank(1)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
Example #10
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 #11
Source File: BackStackShortcutActivityGenerated.java    From shortbread with Apache License 2.0 6 votes vote down vote up
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel("SHORT_LABEL")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(BackStackShortcutActivity.class)
                    .addNextIntent(new Intent(Intent.ACTION_VIEW).setClass(context, EmptyActivity1.class))
                    .addNextIntent(new Intent(Intent.ACTION_VIEW).setClass(context, EmptyActivity2.class))
                    .addNextIntent(new Intent(context, BackStackShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
Example #12
Source File: ResourcesShortcutActivityGenerated.java    From shortbread with Apache License 2.0 6 votes vote down vote up
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(context.getString(34))
            .setLongLabel(context.getString(56))
            .setIcon(Icon.createWithResource(context, 12))
            .setDisabledMessage(context.getString(78))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(ResourcesShortcutActivity.class)
                    .addNextIntent(new Intent(context, ResourcesShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
Example #13
Source File: ShortbreadGenerated.java    From shortbread with Apache License 2.0 6 votes vote down vote up
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    if (shortcuts == null) {
        List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
        List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
        enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
                .setShortLabel("Short label")
                .setIntents(TaskStackBuilder.create(context)
                        .addNextIntent(new Intent(Intent.ACTION_VIEW))
                        .getIntents())
                .setRank(0)
                .build());

        shortcuts = Arrays.asList(enabledShortcuts, disabledShortcuts);
    }

    return shortcuts;
}
 
Example #14
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 #15
Source File: SettingsActivity.java    From Readily with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressLint("NewApi")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
		case android.R.id.home:
			Intent upIntent = NavUtils.getParentActivityIntent(this);
			if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
				TaskStackBuilder.create(this)
						.addNextIntentWithParentStack(upIntent)
						.startActivities();
			} else {
				upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(upIntent);
				finish();
			}
			return true;
	}
	return super.onOptionsItemSelected(item);
}
 
Example #16
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 #17
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 #18
Source File: VideoActivity.java    From evercam-android with GNU Affero General Public License v3.0 5 votes vote down vote up
/************************
 * Private Methods
 ************************/

private void navigateBackToCameraList() {
    if (CamerasActivity.activity == null) {
        if (android.os.Build.VERSION.SDK_INT >= 16) {
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            TaskStackBuilder.create(this)
                    .addNextIntentWithParentStack(upIntent)
                    .startActivities();
        }
    }

    finish();
}
 
Example #19
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 #20
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 #21
Source File: Notifications.java    From boilr with GNU General Public License v3.0 5 votes vote down vote up
private static void statusBarNotifAux(Context context, Alarm alarm, String firingReasonTitle, String firingReasonBody) {
	if(sSmallUpArrowBitmap == null) {
		int tickerGreen = context.getResources().getColor(R.color.tickergreen);
		int tickerRed = context.getResources().getColor(R.color.tickerred);
		sSmallUpArrowBitmap = textAsBitmap("▲", sSmallArrowSize, tickerGreen);
		sBigUpArrowBitmap = textAsBitmap("▲", sBigArrowSize, tickerGreen);
		sSmallDownArrowBitmap = textAsBitmap("▼", sSmallArrowSize, tickerRed);
		sBigDownArrowBitmap = textAsBitmap("▼", sBigArrowSize, tickerRed);
	}
	Notification.Builder notification = new Notification.Builder(context)
		.setContentTitle(firingReasonTitle)
		.setContentText(firingReasonBody)
		.setSmallIcon(R.drawable.ic_notification)
		.setLights(0xFFFF0000, 333, 333) // Blink in red ~3 times per second.
		.setOngoing(false)
		.setAutoCancel(true);
	if(isDirectionUp(alarm)) {
		notification.setLargeIcon(sSmallUpArrowBitmap);
	} else {
		notification.setLargeIcon(sSmallDownArrowBitmap);
	}
	Intent alarmSettingsIntent = new Intent(context, AlarmSettingsActivity.class);
	alarmSettingsIntent.putExtra(AlarmSettingsActivity.alarmID, alarm.getId());
	alarmSettingsIntent.putExtra(AlarmSettingsActivity.alarmType, alarm.getClass().getSimpleName());
	alarmSettingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	PendingIntent pendingIntent;
	if(Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
		pendingIntent = TaskStackBuilder.create(context)
							.addNextIntentWithParentStack(alarmSettingsIntent)
							.getPendingIntent(alarm.getId(), PendingIntent.FLAG_UPDATE_CURRENT);
	} else {
		pendingIntent = PendingIntent.getActivity(context, alarm.hashCode(), alarmSettingsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
	}
	notification.setContentIntent(pendingIntent);
	//notification.setPriority(Notification.PRIORITY_DEFAULT); API 16 only
	NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
	nm.cancel(alarm.hashCode());
	nm.notify(alarm.hashCode(), notification.getNotification());
}
 
Example #22
Source File: DetailFragment.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // Some small additions to handle "up" navigation correctly
            Intent upIntent = NavUtils.getParentActivityIntent(getActivity());
            upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

            // Check if up activity needs to be created (usually when
            // detail screen is opened from a notification or from the
            // Wearable app
            if (NavUtils.shouldUpRecreateTask(getActivity(), upIntent)
                    || getActivity().isTaskRoot()) {

                // Synthesize parent stack
                TaskStackBuilder.create(getActivity())
                        .addNextIntentWithParentStack(upIntent)
                        .startActivities();
            }

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                // On Lollipop+ we finish so to run the nice animation
                getActivity().finishAfterTransition();
                return true;
            }

            // Otherwise let the system handle navigating "up"
            return false;
        case R.id.map:
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(Constants.MAPS_INTENT_URI +
                    Uri.encode(mAttraction.name + ", " + mAttraction.city)));
            startActivity(intent);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #23
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 #24
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 #25
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 #26
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 #27
Source File: BaseActivity.java    From mConference-Framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createBackStack(Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        TaskStackBuilder builder = TaskStackBuilder.create(this);
        builder.addNextIntentWithParentStack(intent);
        builder.startActivities();
    }
    else {
        startActivity(intent);
        finish();
    }
}
 
Example #28
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 #29
Source File: WidgetProvider.java    From Birdays with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);
    if (intent.getAction() != null && intent.getAction().equals(ACTION_ON_CLICK)) {
        long timeStamp = intent.getLongExtra(Constants.TIME_STAMP, 0);
        Intent resultIntent = new Intent(context, DetailActivity.class);
        resultIntent.putExtra(Constants.TIME_STAMP, timeStamp);
        resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        TaskStackBuilder.create(context).addNextIntentWithParentStack(resultIntent).startActivities();
    }
}
 
Example #30
Source File: ScannerActivity.java    From ShadowsocksRR with Apache License 2.0 5 votes vote down vote up
private void navigateUp() {
    Intent intent = getParentActivityIntent();
    if (shouldUpRecreateTask(intent) || isTaskRoot()) {
        TaskStackBuilder.create(this).addNextIntentWithParentStack(intent).startActivities();
    } else {
        finish();
    }
}