Java 类android.app.TaskStackBuilder 实例源码

项目:FBEventSync    文件:CalendarSyncAdapter.java   
private void createAuthNotification()
{
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(getContext(), AuthenticatorActivity.AUTH_NOTIFICATION_CHANNEL_ID)
                .setContentTitle(getContext().getString(R.string.sync_ntf_needs_reauthentication_title))
                .setContentText(getContext().getString(R.string.sync_ntf_needs_reauthentication_description))
                .setSmallIcon(R.mipmap.ic_launcher)
                .setAutoCancel(true);

    Intent intent = new Intent(getContext(), AuthenticatorActivity.class);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, getContext().getString(R.string.account_type));
    intent.putExtra(AuthenticatorActivity.ARG_AUTH_TOKEN_TYPE, AuthenticatorActivity.ARG_AUTH_TOKEN_TYPE);
    intent.putExtra(AuthenticatorActivity.ARG_IS_ADDING_NEW_ACCOUNT, false);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getContext());
    stackBuilder.addParentStack(AuthenticatorActivity.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);

    NotificationManager ntfMgr =
            (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
    ntfMgr.notify(AuthenticatorActivity.AUTH_NOTIFICATION_ID, builder.build());
}
项目:shortbread    文件:ShortbreadGenerated.java   
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;
}
项目:shortbread    文件:ResourcesShortcutActivityGenerated.java   
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);
}
项目:shortbread    文件:BackStackShortcutActivityGenerated.java   
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);
}
项目:shortbread    文件:TwoShortcutActivitiesGenerated.java   
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);
}
项目:shortbread    文件:AdvancedShortcutActivityGenerated.java   
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);
}
项目:shortbread    文件:TwoMethodShortcutActivitiesGenerated.java   
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);
}
项目:shortbread    文件:TwoMethodShortcutsActivityGenerated.java   
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);
}
项目:storj_hoststats_app    文件:AlarmReceiver.java   
private void sendNodeOfflineNotification(StorjNode storjNode) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    if(prefs.getBoolean(mContext.getString(R.string.pref_enable_notifications),true)) {
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);

        Intent detailNotificationIntent = new Intent(mContext, StorjNodeDetailActivity.class);
        detailNotificationIntent.putExtra(StorjNodeDetailActivity.EXTRA_NODEID, storjNode.getNodeID().getValue());
        stackBuilder.addNextIntentWithParentStack(detailNotificationIntent);

        PendingIntent operation = stackBuilder.getPendingIntent(storjNode.getNodeID().getValue().hashCode(), PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext)
                .setSmallIcon(R.drawable.storj_symbol)
                .setContentTitle(storjNode.getSimpleName().getValue())
                .setContentIntent(operation)
                .setContentText(mContext.getString(R.string.node_is_offline, storjNode.getSimpleName().getValue()));

        NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(storjNode.getNodeID().hashCode(), mBuilder.build());
    }
}
项目:storj_hoststats_app    文件:AlarmReceiver.java   
private void sendNewUserAgentVersionNotification() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    if(prefs.getBoolean(mContext.getString(R.string.pref_enable_notifications),true)) {
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
        stackBuilder.addNextIntentWithParentStack(new Intent(mContext, MainActivity.class));

        PendingIntent operation = stackBuilder.getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext)
                .setSmallIcon(R.drawable.storj_symbol)
                .setContentTitle(mContext.getResources().getString(R.string.new_useragent_version))
                .setContentIntent(operation)
                .setContentText(mContext.getResources().getString(R.string.new_useragent_version_details));

        NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(1, mBuilder.build());
    }
}
项目:FindX    文件:digiPune.java   
void reminder()
    {

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);

        mBuilder.setSmallIcon(R.drawable.sos);
        mBuilder.setContentTitle("Reminder !");
        mBuilder.setContentText(reminder_text);

        Intent resultIntent = new Intent(this, Location_event.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addParentStack(Location_event.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);

// notificationID allows you to update the notification later on.
        mNotificationManager.notify(0, mBuilder.build());

    }
项目:vbluno_android_ibeacon    文件:BeaconReferenceApplication.java   
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());
}
项目:science-journal    文件:ExperimentDetailsFragment.java   
private void goToExperimentList() {
    Intent upIntent = NavUtils.getParentActivityIntent(getActivity());
    if (upIntent == null) {
        // This is cheating a bit.  Currently, upIntent has only been observed to be null
        // when we're using panes mode, so here we just assume usePanes==true.
        Intent intent =
                MainActivity.launchIntent(getActivity(), R.id.navigation_item_experiments,
                        true);
        getActivity().startActivity(intent);
        getActivity().finish();
        return;
    }
    if (NavUtils.shouldUpRecreateTask(getActivity(), upIntent) || getArguments().getBoolean(
            ARG_CREATE_TASK, false)) {
        upIntent.putExtra(MainActivity.ARG_SELECTED_NAV_ITEM_ID,
                R.id.navigation_item_experiments);
        upIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        // TODO: Transition animation
        TaskStackBuilder.create(getActivity()).addNextIntentWithParentStack(upIntent)
                .startActivities();
    } else {
        NavUtils.navigateUpTo(getActivity(), upIntent);
    }
}
项目:privacy-friendly-netmonitor    文件:PassiveService.java   
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());
}
项目:AndroidSamples    文件:StageService.java   
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);
}
项目:Learn    文件:LearnService.java   
public void showNotification() {
    NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_favorite_black_24dp)
            .setContentTitle("Test")
            .setContentText("123");
    // 点击通知触发的 Intent
    Intent resulteIntent = new Intent(this, MainActivity.class);
    // 任务栈 Builder
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resulteIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(resultPendingIntent);
    // 构建通知
    Notification notification = builder.build();
    // 通知管理器
    NotificationManager notificationMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationMgr.notify(NOTIFY_ID, notification);
}
项目:udacity-capstone    文件:EventsWidgetProvider.java   
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    // Perform this loop procedure for each App Widget that belongs to this provider
    for (int appWidgetId : appWidgetIds) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_events_list);

        // Create an Intent to launch MainActivity
        Intent intent = new Intent(context, EventsActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        views.setOnClickPendingIntent(R.id.widget, pendingIntent);

        // Set up the collection
        setRemoteAdapter(context, views);

        Intent clickIntentTemplate = new Intent(context, ProductActivity.class);
        PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context)
                .addNextIntentWithParentStack(clickIntentTemplate)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate);
        views.setEmptyView(R.id.widget_list, R.id.widget_empty);

        // Tell the AppWidgetManager to perform an update on the current app widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}
项目:Mycroft-Android    文件:MycroftApplication.java   
private void sendNotification() {
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(this)
                    .setContentTitle(getString(R.string.beacon_notification_title))
                    .setContentText(getString(R.string.beacon_notification_content))
                    .setSmallIcon(R.drawable.ic_mycroft);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addNextIntent(new Intent(this, BeaconActivity.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());
}
项目:LETO-Toggl_Android    文件:NotificationActionHandler.java   
private void showRemindInfoNotification(Context context){
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle("LETO Toggl")
            .setContentText("Toggl stopped. Will remind you to start tracking in 30 minutes!")
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setVibrate(null)
            .setColor(ContextCompat.getColor(context, R.color.flat_red))
            .setCategory(Notification.CATEGORY_MESSAGE)
            .setPriority(Notification.PRIORITY_HIGH)
            .setShowWhen(true)
            .setAutoCancel(true)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .setStyle(new NotificationCompat.BigTextStyle().bigText("Toggl stopped. Will remind you to start tracking in 30 minutes!"))
            .setSmallIcon(R.drawable.ic_stop);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addNextIntent(new Intent(context, MainActivity.class));
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NotificationActionHandler.STOP_ID, builder.build());
}
项目:fakeweibo    文件:ComposeTweetService.java   
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());
}
项目:android-diplicity    文件:NotificationReceiveActivity.java   
private void startGameActivity(String gameID) {
    handleReq(
            gameService.GameLoad(gameID),
            new Sendable<SingleContainer<Game>>() {
                @Override
                public void send(SingleContainer<Game> gameSingleContainer) {
                    Intent mainIntent = new Intent(NotificationReceiveActivity.this, MainActivity.class);
                    mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                    Intent gameIntent;
                    if (gameSingleContainer.Properties.NewestPhaseMeta != null && gameSingleContainer.Properties.NewestPhaseMeta.size() > 0) {
                        gameIntent = GameActivity.startGameIntent(NotificationReceiveActivity.this, gameSingleContainer.Properties, gameSingleContainer.Properties.NewestPhaseMeta.get(0));
                    } else {
                        gameIntent = GameActivity.startGameIntent(NotificationReceiveActivity.this, gameSingleContainer.Properties, null);
                    }
                    if (android.os.Build.VERSION.SDK_INT > 15) {
                        TaskStackBuilder.create(NotificationReceiveActivity.this)
                                .addNextIntent(mainIntent)
                                .addNextIntent(gameIntent).startActivities();
                    } else {
                        startActivity(gameIntent);
                    }
                    finish();

                }
            }, getResources().getString(R.string.loading_state));
}
项目:talkback    文件:NotificationTest.java   
private void showSimpleNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext())
            .setSmallIcon(android.R.drawable.ic_notification_overlay)
            .setAutoCancel(true)
            .setContentTitle(getString(R.string.normal_notification_title))
            .setContentText(getString(R.string.normal_notification_text))
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getContext());
    stackBuilder.addParentStack(MainActivity.class);

    Intent resultIntent = new Intent(getContext(), MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);

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

    NotificationManager notificationManager = (NotificationManager)
            getContext().getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID_MAIN_MENU, builder.build());
}
项目:investickation    文件:ActivityRunningFragment.java   
/**
 * Helper to set Notification when the alarm goes off
 */
private void setNotification() {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext);
    mBuilder.setSmallIcon(R.mipmap.ic_bug_report_white_36dp);
    mBuilder.setContentTitle("Found a Tick?");
    mBuilder.setContentText("Click here to make an Observation of encountered Tick!");
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    mBuilder.setSound(uri);

    Intent resultIntent = new Intent(mContext, ObservationMasterActivity.class);
    // put the extras in addObservationIntent to perform fragment Transaction efficiently.
    resultIntent.putExtra(UserActivityMasterActivity.KEY_ACTIVITY_ADD_OBS, 1);
    resultIntent.putExtra(UserActivityMasterActivity.KEY_ACTIVITY_ID, ongoingActivityObj.getId());
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    stackBuilder.addParentStack(ObservationMasterActivity.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) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    // notificationID allows you to update the notification later on.
    mNotificationManager.notify(12345, mBuilder.build());
}
项目:music-app    文件:PlayingNowActivity.java   
@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
                NavUtils.navigateUpTo(this, upIntent);

            return true;
    }

    return super.onOptionsItemSelected(item);
}
项目:music-app    文件:SearchActivity.java   
@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
                NavUtils.navigateUpTo(this, upIntent);

            return true;
    }

    return super.onOptionsItemSelected(item);
}
项目:android-ble    文件:BluetoothLeService.java   
private void setNotification() {
    final Intent resultIntent = new Intent(this, MainActivity.class);
    final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder = new NotificationCompat.Builder(this)
            .setContentText(getString(R.string.notification_bt_on))
            .setContentTitle(getString(R.string.device_hive))
            .setSmallIcon(R.drawable.ic_le_service)
            .setAutoCancel(false)
            .setOngoing(true)
            .setContentIntent(resultPendingIntent);

    mNotificationManager.notify(LE_NOTIFICATION_ID, mBuilder.build());
}
项目:Ships    文件:Utils.java   
public static void sendNotification(final Context context,final String postfix,final String message){
    final Notification.Builder mBuilder =
            new Notification.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(context.getText(R.string.app_name)+" "+postfix)
            .setContentText(message);
    // Creates an explicit intent for an Activity in your app
    final 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.
    final 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);
    mBuilder.setContentIntent(resultPendingIntent);
    final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (mNotificationManager!=null) {
           // mId allows you to update the notification later on.
           int mId = 0;
           mNotificationManager.notify(mId, mBuilder.build());

           Analytics.getInstance().logEvent(TAG, "sendNotification", "message");
       }
}
项目:hypertrack-live-android    文件:Placeline.java   
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    drawer.closeDrawers();
    if (item.getItemId() == R.id.edit_profile)
        startActivity(new Intent(this, Profile.class));

    else if (item.getItemId() == R.id.start_tracking_toggle) {
        if (ActionManager.getSharedManager(this).shouldRestoreState()) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Can't do stop tracking.");
            builder.setMessage("Ongoing location sharing trip is active. Stop trip first.");
            builder.setNegativeButton("No", null);
            builder.setPositiveButton("Goto live trip", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    TaskStackBuilder.create(Placeline.this)
                            .addNextIntentWithParentStack(new Intent(Placeline.this, Home.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                            .startActivities();
                }
            });
            builder.show();
            return true;
        }
        startHyperTrackTracking();
    }
    return true;
}
项目:BuddyBook    文件:BuddyBookWidgetProvider.java   
@SuppressLint("PrivateResource")
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int widgetId : appWidgetIds) {
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.buddy_widget_list);


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            setRemoteAdapter(context, remoteViews);
        } else {
            setRemoteAdapterV11(context, remoteViews);
        }

        Intent clickIntentTemplate = new Intent(context, DetailActivity.class);

        PendingIntent pendingIntentTemplate = TaskStackBuilder.create(context)
                .addNextIntentWithParentStack(clickIntentTemplate)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        remoteViews.setPendingIntentTemplate(R.id.widget_list, pendingIntentTemplate);
        remoteViews.setEmptyView(R.id.widget_list, R.id.widget_empty);
        remoteViews.setContentDescription(R.id.widget_list, context.getString(R.string.widget_cd));
        appWidgetManager.updateAppWidget(widgetId, remoteViews);

        appWidgetManager.notifyAppWidgetViewDataChanged(widgetId, R.id.widget_list);

    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
项目:shortbread    文件:TargetShortcutActivityGenerated.java   
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, TargetShortcutActivity.class))
            .setActivity(new ComponentName(context, EmptyActivity1.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(TargetShortcutActivity.class)
                    .addNextIntent(new Intent(context, TargetShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
项目:shortbread    文件:DisabledShortcutActivityGenerated.java   
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    disabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, DisabledShortcutActivity.class))
            .setDisabledMessage("DISABLED_MESSAGE")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(DisabledShortcutActivity.class)
                    .addNextIntent(new Intent(context, DisabledShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
项目:shortbread    文件:MethodShortcutActivityGenerated.java   
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());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
项目:shortbread    文件:SimpleShortcutActivityGenerated.java   
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());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
项目:fitnotifications    文件:NLService.java   
/**
 * 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);
}
项目:buildAPKsSamples    文件:NotificationsActivity.java   
public void onPostDirect(View v) {
    Notification.Builder builder = new Notification.Builder(this)
            .setTicker("Direct Notification")
            .setSmallIcon(android.R.drawable.stat_notify_chat)
            .setContentTitle("Direct Notification")
            .setContentText("This will open the content viewer")
            .setAutoCancel(true)
            .setContentIntent(TaskStackBuilder.create(this)
                    .addParentStack(ContentViewActivity.class)
                    .addNextIntent(new Intent(this, ContentViewActivity.class)
                            .putExtra(ContentViewActivity.EXTRA_TEXT, "From Notification"))
                    .getPendingIntent(0, 0));
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify("direct_tag", R.id.direct_notification, builder.getNotification());
}
项目:buildAPKsSamples    文件:InterstitialMessageActivity.java   
public void onViewContent(View v) {
    TaskStackBuilder.create(this)
            .addParentStack(ContentViewActivity.class)
            .addNextIntent(new Intent(this, ContentViewActivity.class)
                    .putExtra(ContentViewActivity.EXTRA_TEXT, "From Interstitial Notification"))
            .startActivities();
    finish();
}
项目:Android-Notifications-Sample    文件:NotificationReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    //Do some operations, like loading values from a file, and show it in the notification or pass it in the calledActivity
    String loadedString = "This is a string loaded from the Receiver";

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    //Building our custom Notification
    NotificationCompat.Builder mBuilder =
            (NotificationCompat.Builder) new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_flag) //Set icon
                    .setContentTitle("Notification Title")
                    .setContentText("Click to call calledActivity")
                    .setSound(alarmSound)
                    .setColor(Color.argb(0,21,101,192)) //Color your notification
                    .setVibrate(new long[]{300, 300, 300, 300, 300}) //Vibration intensity
                    .setAutoCancel(true);

    //setting activity called clicking on the notification
    Intent resultIntent = new Intent(context, calledActivity.class);
    resultIntent.putExtra(calledActivity.WORD, loadedString);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    //Building virtual stack, allowing the user to press back to go back to the main activity
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(calledActivity.class);
    stackBuilder.addNextIntent(resultIntent);

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

    mBuilder.setContentIntent(resultPendingIntent);
    notificationManager.notify(MainActivity.notifId, mBuilder.build());
}
项目:Pocket-Plays-for-Twitch    文件:NotificationReceiver.java   
private Notification createStreamNotification(StreamInfo stream, @Nullable Bitmap image, boolean showViewers, Context context) {
    Intent resultIntent = LiveStreamActivity.createLiveStreamIntent(stream, false, context);

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

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

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

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

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

    return mBuilder.build();
}
项目:FindX    文件:digiPune.java   
void startData(){
        try {
            setMobileDataEnabled(this.getApplicationContext(), true);
        }
        catch(Exception e){
            //    Toast.makeText(this,e.toString(),Toast.LENGTH_SHORT).show();
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);

            mBuilder.setSmallIcon(R.drawable.sos);
            mBuilder.setContentTitle("Reminder !");
            mBuilder.setContentText(e.toString());

            Intent resultIntent = new Intent(this, Location_event.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(Location_event.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);

// notificationID allows you to update the notification later on.
            mNotificationManager.notify(0, mBuilder.build());

        }
    }
项目:FindX    文件:digiPune.java   
void stopData()
    {
        try {
            setMobileDataEnabled(this.getApplicationContext(), false);
        }
        catch(Exception e){
            // Toast.makeText(this,e.toString(),Toast.LENGTH_SHORT).show();
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);

            mBuilder.setSmallIcon(R.drawable.sos);
            mBuilder.setContentTitle("Reminder !");
            mBuilder.setContentText(e.toString());

            Intent resultIntent = new Intent(this, Location_event.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(Location_event.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);

// notificationID allows you to update the notification later on.
            mNotificationManager.notify(0, mBuilder.build());

        }
    }