android.support.v4.app.TaskStackBuilder Java Examples

The following examples show how to use android.support.v4.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: FeedActivity.java    From android-mvp-interactor-architecture with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        // Respond to the action bar's Up/Home button
        case android.R.id.home:
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                // This activity is NOT part of this app's task, so create a new task
                // when navigating up, with a synthesized back stack.
                TaskStackBuilder.create(this)
                        // Add all of this activity's parents to the back stack
                        .addNextIntentWithParentStack(upIntent)
                        // Navigate up to the closest parent
                        .startActivities();
            } else {
                // This activity is part of this app's task, so simply
                // navigate up to the logical parent activity.
                NavUtils.navigateUpTo(this, upIntent);
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #2
Source File: InAppChatImpl.java    From mobile-messaging-sdk-android with Apache License 2.0 6 votes vote down vote up
@NonNull
private TaskStackBuilder stackBuilderForNotificationTap(Message message) {
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    Bundle messageBundle = MessageBundleMapper.messageToBundle(message);
    Class[] classes = propertyHelper().findClasses(MobileMessagingChatProperty.ON_MESSAGE_TAP_ACTIVITY_CLASSES);
    if (classes != null) {
        for (Class cls : classes) {
            stackBuilder.addNextIntent(new Intent(context, cls)
                    .setAction(Event.NOTIFICATION_TAPPED.getKey())
                    .putExtras(messageBundle));
        }
    }

    NotificationSettings notificationSettings = MobileMessagingCore.getInstance(context).getNotificationSettings();
    if (stackBuilder.getIntentCount() == 0 && notificationSettings != null && notificationSettings.getCallbackActivity() != null) {
        stackBuilder.addNextIntent(new Intent(context, notificationSettings.getCallbackActivity())
                .setAction(Event.NOTIFICATION_TAPPED.getKey())
                .putExtras(messageBundle));
    }

    return stackBuilder;
}
 
Example #3
Source File: ArticleCollectionActivity.java    From aard2-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        Intent upIntent = Intent.makeMainActivity(new ComponentName(this, MainActivity.class));
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            TaskStackBuilder.create(this)
                    .addNextIntent(upIntent).startActivities();
            finish();
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivity(upIntent);
            finish();
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #4
Source File: LoginActivity.java    From v2ex-daily-android with Apache License 2.0 6 votes vote down vote up
@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);
                NavUtils.navigateUpTo(this, upIntent);
            }
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #5
Source File: NavControllerTest.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeepLinkIntent() {
    NavController navController = createNavController();
    navController.setGraph(R.navigation.nav_simple);

    Bundle args = new Bundle();
    args.putString("test", "test");
    TaskStackBuilder taskStackBuilder = navController.createDeepLink()
            .setDestination(R.id.second_test)
            .setArguments(args)
            .createTaskStackBuilder();

    Intent intent = taskStackBuilder.editIntentAt(0);
    assertThat(intent, is(notNullValue()));
    navController.onHandleDeepLink(intent);

    // The original Intent should be untouched and safely writable to a Parcel
    Parcel p = Parcel.obtain();
    intent.writeToParcel(p, 0);
}
 
Example #6
Source File: ManageReposActivity.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_add_repo:
            showAddRepo();
            return true;
        case android.R.id.home:
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            if (NavUtils.shouldUpRecreateTask(this, upIntent) || isTaskRoot()) {
                TaskStackBuilder.create(this)
                        .addNextIntentWithParentStack(upIntent)
                        .startActivities();
            } else {
                NavUtils.navigateUpTo(this, upIntent);
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #7
Source File: UserActivity.java    From v2ex-daily-android with Apache License 2.0 6 votes vote down vote up
@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);
                NavUtils.navigateUpTo(this, upIntent);
            }
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #8
Source File: HyperionGrabberTileService.java    From hyperion-android-grabber with MIT License 6 votes vote down vote up
/** Starts the Settings Activity if connection settings are missing
 *
 * @return true if setup was started
 */
private boolean startSetupIfNeeded(){
    Preferences preferences = new Preferences(getApplicationContext());
    if (TextUtils.isEmpty(preferences.getString(R.string.pref_key_host, null)) || preferences.getInt(R.string.pref_key_port, -1) == -1){
        Intent settingsIntent = new Intent(this, SettingsActivity.class);
        settingsIntent.putExtra(SettingsActivity.EXTRA_SHOW_TOAST_KEY, SettingsActivity.EXTRA_SHOW_TOAST_SETUP_REQUIRED_FOR_QUICK_TILE);
        settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        // Use TaskStackBuilder to make sure the MainActivity opens when the SettingsActivity is closed
        TaskStackBuilder.create(this)
                .addNextIntentWithParentStack(settingsIntent)
                .startActivities();

        Intent closeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        sendBroadcast(closeIntent);

        return true;
    }

    return false;
}
 
Example #9
Source File: DebatesActivity.java    From kaif-android with Apache License 2.0 6 votes vote down vote up
@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);
        NavUtils.navigateUpTo(this, upIntent);
      }
      return true;
    case R.id.action_open_link:
      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.setData(article.getPermaLink());
      intent.addCategory(Intent.CATEGORY_BROWSABLE);
      this.startActivity(intent);
      return true;
  }

  return super.onOptionsItemSelected(item);
}
 
Example #10
Source File: TopicActivity.java    From v2ex-daily-android with Apache License 2.0 6 votes vote down vote up
@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);
                NavUtils.navigateUpTo(this, upIntent);
            }
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #11
Source File: Utils.java    From physical-web with Apache License 2.0 6 votes vote down vote up
/**
 * Surface a notification to the user that the Physical Web is broadcasting. The notification
 * specifies the transport or URL that is being broadcast and cannot be swiped away.
 * @param context
 * @param stopServiceReceiver
 * @param broadcastNotificationId
 * @param title
 * @param text
 * @param filter
 */
public static void createBroadcastNotification(Context context,
    BroadcastReceiver stopServiceReceiver, int broadcastNotificationId, CharSequence title,
    CharSequence text, String filter) {
  Intent resultIntent = new Intent();
  TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
  stackBuilder.addParentStack(MainActivity.class);
  stackBuilder.addNextIntent(resultIntent);
  PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
      PendingIntent.FLAG_UPDATE_CURRENT);
  context.registerReceiver(stopServiceReceiver, new IntentFilter(filter));
  PendingIntent pIntent = PendingIntent.getBroadcast(context, 0, new Intent(filter),
      PendingIntent.FLAG_UPDATE_CURRENT);
  NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
      .setSmallIcon(R.drawable.ic_leak_add_white_24dp)
      .setContentTitle(title)
      .setContentText(text)
      .setOngoing(true)
      .addAction(android.R.drawable.ic_menu_close_clear_cancel,
          context.getString(R.string.stop), pIntent);
  builder.setContentIntent(resultPendingIntent);

  NotificationManager notificationManager = (NotificationManager) context.getSystemService(
      Context.NOTIFICATION_SERVICE);
  notificationManager.notify(broadcastNotificationId, builder.build());
}
 
Example #12
Source File: RegistActivity.java    From weixin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home://返回上一菜单页
		AppToast.getToast().show("返回上一页");
		Intent upIntent = NavUtils.getParentActivityIntent(this);
		if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
			TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
		} else {
			upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			NavUtils.navigateUpTo(this, upIntent);
		}
		break;

	default:
		break;
	}
	return super.onOptionsItemSelected(item);
}
 
Example #13
Source File: StepService.java    From healthgo with GNU General Public License v3.0 6 votes vote down vote up
public void myStartForeground() {
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("计步器")
                    .setContentText("正在运行");

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


    startForeground(1, mBuilder.build());
}
 
Example #14
Source File: FeedActivity.java    From android-mvp-architecture with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        // Respond to the action bar's Up/Home button
        case android.R.id.home:
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                // This activity is NOT part of this app's task, so create a new task
                // when navigating up, with a synthesized back stack.
                TaskStackBuilder.create(this)
                        // Add all of this activity's parents to the back stack
                        .addNextIntentWithParentStack(upIntent)
                        // Navigate up to the closest parent
                        .startActivities();
            } else {
                // This activity is part of this app's task, so simply
                // navigate up to the logical parent activity.
                NavUtils.navigateUpTo(this, upIntent);
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #15
Source File: NotificationScheduler.java    From Muslim-Athkar-Islamic-Reminders with MIT License 6 votes vote down vote up
public static void showNotification(Context context,Class<?> cls,String title,String content)
{
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    Intent notificationIntent = new Intent(context, cls);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(cls);
    stackBuilder.addNextIntent(notificationIntent);

    PendingIntent pendingIntent = stackBuilder.getPendingIntent(DAILY_REMINDER_REQUEST_CODE, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context,context.getPackageName());

    Notification notification = builder.setContentTitle(title)
            .setContentText(content)
            .setAutoCancel(true)
            .setSound(alarmSound)
            .setSmallIcon(R.drawable.app_icon_144)
            .setContentIntent(pendingIntent).build();

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(DAILY_REMINDER_REQUEST_CODE, notification);

}
 
Example #16
Source File: WebActivity.java    From Small with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (upIntent == null) {
            finish();
        } else {
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                // This activity is NOT part of this app's task, so create a new task
                // when navigating up, with a synthesized back stack.
                TaskStackBuilder.create(this)
                        // Add all of this activity's parents to the back stack
                        .addNextIntentWithParentStack(upIntent)
                                // Navigate up to the closest parent
                        .startActivities();
            } else {
                // This activity is part of this app's task, so simply
                // navigate up to the logical parent activity.
                NavUtils.navigateUpTo(this, upIntent);
            }
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #17
Source File: BaseActivity.java    From privacy-friendly-qr-scanner with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Enables back navigation for activities that are launched from the NavBar. See
 * {@code AndroidManifest.xml} to find out the parent activity names for each activity.
 * @param intent
 */
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 #18
Source File: NotificationItem.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
public PendingIntent getPendingIntent(Context context) {
  Intent     intent           = new Intent(context, ConversationActivity.class);
  Recipients notifyRecipients = threadRecipients != null ? threadRecipients : recipients;
  if (notifyRecipients != null) intent.putExtra("recipients", notifyRecipients.getIds());

  intent.putExtra("thread_id", threadId);
  intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));

  return TaskStackBuilder.create(context)
                         .addNextIntentWithParentStack(intent)
                         .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example #19
Source File: DownloadManager.java    From Android-Remote with GNU General Public License v3.0 5 votes vote down vote up
private PendingIntent buildNotificationIntent() {
    Intent intent = new Intent(mContext, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(ClementineMediaSessionNotification.EXTRA_NOTIFICATION_ID,
            NOTIFICATION_ID_DOWNLOADS);

    // Create a TaskStack, so the app navigates correctly backwards
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(intent);
    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example #20
Source File: ForwardingService.java    From FwdPortForwardingApp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Construct a notification
 */
private void showForwardingEnabledNotification() {
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_fwd_24dp)
                    .setContentTitle(getString(R.string.notification_forwarding_active_title))
                    .setContentText(getString(R.string.notification_forwarding_touch_disable_text));

    mBuilder.setColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));

    // Creates an explicit intent for an Activity in your app
    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);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification = mBuilder.build();
    notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT | Notification.DEFAULT_LIGHTS;

    // mId allows you to update the notification later on.
    mNotificationManager.notify(NOTIFICATION_ID, notification);
}
 
Example #21
Source File: MasterService.java    From 600SeriesAndroidUploader with MIT License 5 votes vote down vote up
private void showDisconnectionNotification(String title, String message) {

        String channel = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? "error" : "";

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this, channel)
                        .setPriority(PRIORITY_MAX)
                        .setSmallIcon(android.R.drawable.stat_notify_error)
                        .setContentTitle(title)
                        .setContentText(message)
                        .setTicker(message)
                        .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});

        // 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);
        mNotificationManager.notify(USB_DISCONNECT_NOFICATION_ID, mBuilder.build());
    }
 
Example #22
Source File: BaseActivity.java    From privacy-friendly-pedometer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Enables back navigation for activities that are launched from the NavBar. See
 * {@code AndroidManifest.xml} to find out the parent activity names for each activity.
 *
 * @param intent
 */
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 #23
Source File: AbstractBarterLiActivity.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
/**
 * Moves up in the hierarchy using the Support meta data specified in manifest
 */
private void doUpNavigation() {
    final Intent upIntent = NavUtils.getParentActivityIntent(this);

    if (upIntent == null) {

        NavUtils.navigateUpFromSameTask(this);

    } else {
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is NOT part of this app's task, so create a
            // new
            // task
            // when navigating up, with a synthesized back stack.
            TaskStackBuilder.create(this)
                    // Add all of this activity's parents to the back stack
                    .addNextIntentWithParentStack(upIntent)
                            // Navigate up to the closest parent
                    .startActivities();
        } else {
            // This activity is part of this app's task, so simply
            // navigate up to the logical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
    }

}
 
Example #24
Source File: BaseActivity.java    From privacy-friendly-ludo with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Enables back navigation for activities that are launched from the NavBar. See
 * {@code AndroidManifest.xml} to find out the parent activity names for each activity.
 * @param intent
 */
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 #25
Source File: GroupsService.java    From Saude-no-Mapa with MIT License 5 votes vote down vote up
private void showNotification(Grupo grupo) {
    Intent intent = new Intent(this, ChatActivity.class);

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

    intent.putExtra(GROUP_KEY, grupo);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    int notId = new Random().nextInt();

    stackBuilder.addNextIntent(intent);
    PendingIntent pendingIntent =
            stackBuilder.getPendingIntent(notId, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.app_icon)
            .setContentTitle(getString(R.string.app_name))
            .setContentText("Você possui mensagens não lidas no grupo: " + grupo.getDescricao())
            .setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notId, notificationBuilder.build());
}
 
Example #26
Source File: BaseActivity.java    From privacy-friendly-shopping-list with Apache License 2.0 5 votes vote down vote up
/**
 * Enables back navigation for activities that are launched from the NavBar. See
 * {@code AndroidManifest.xml} to find out the parent activity names for each activity.
 *
 * @param intent
 */
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 #27
Source File: BaseActivity.java    From EosCommander with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

        case android.R.id.home:
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            if ( null != upIntent ) {
                upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                    // This activity is NOT part of this app's task, so create a new task
                    // when navigating up, with a synthesized back stack.
                    TaskStackBuilder.create(this)
                            // Add all of this activity's parents to the back stack
                            .addNextIntentWithParentStack(upIntent)
                            // Navigate up to the closest parent
                            .startActivities();
                }
                else {
                    // This activity is part of this app's task, so simply
                    // navigate up to the logical parent activity.
                    NavUtils.navigateUpTo(this, upIntent);
                }
            }
            else {
                onBackPressed();
            }


            return true;
    }

    return super.onOptionsItemSelected( item );
}
 
Example #28
Source File: Signal.java    From react-native-audio-streaming with MIT License 5 votes vote down vote up
public void showNotification() {
    remoteViews = new RemoteViews(context.getPackageName(), R.layout.streaming_notification_player);
    notifyBuilder = new Notification.Builder(this.context)
            .setSmallIcon(android.R.drawable.ic_lock_silent_mode_off) // TODO Use app icon instead
            .setContentText("")
            .setOngoing(true)
            .setContent(remoteViews);

    Intent resultIntent = new Intent(this.context, this.clsActivity);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.context);
    stackBuilder.addParentStack(this.clsActivity);
    stackBuilder.addNextIntent(resultIntent);

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

    notifyBuilder.setContentIntent(resultPendingIntent);
    remoteViews.setOnClickPendingIntent(R.id.btn_streaming_notification_play, makePendingIntent(BROADCAST_PLAYBACK_PLAY));
    remoteViews.setOnClickPendingIntent(R.id.btn_streaming_notification_stop, makePendingIntent(BROADCAST_EXIT));
    notifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel =
                new NotificationChannel("com.audioStreaming", "Audio Streaming",
                        NotificationManager.IMPORTANCE_HIGH);
        if (notifyManager != null) {
            notifyManager.createNotificationChannel(channel);
        }

        notifyBuilder.setChannelId("com.audioStreaming");
        notifyBuilder.setOnlyAlertOnce(true);
        
    }
    notifyManager.notify(NOTIFY_ME_ID, notifyBuilder.build());
}
 
Example #29
Source File: ExpensesWidgetProvider.java    From Expense-Tracker-App with MIT License 5 votes vote down vote up
@Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        for (int appWidgetId : appWidgetIds){
            Intent expenseDetailActivity = new Intent(context, ExpenseDetailActivity.class);
            Intent mainActivityIntent = new Intent(context, MainActivity.class);

            // Creating stack for builder item click
            TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
            taskStackBuilder.addParentStack(MainActivity.class);
            taskStackBuilder.addNextIntent(mainActivityIntent);
            taskStackBuilder.addNextIntent(expenseDetailActivity);
            PendingIntent itemClickPendingIntent = taskStackBuilder.getPendingIntent(0 ,PendingIntent.FLAG_UPDATE_CURRENT);

            // Create pending intent for clicking the whole view, not an item
            PendingIntent mainPendingIntent = PendingIntent.getActivity(context, 0, mainActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            Intent widgetServiceIntent = new Intent(context, ExpensesWidgetService.class);
//            widgetServiceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
//            widgetServiceIntent.setData(Uri.parse(widgetServiceIntent.toUri(Intent.URI_INTENT_SCHEME)));

            RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
            remoteView.setOnClickPendingIntent(R.id.general_layout, mainPendingIntent);

            remoteView.setEmptyView(R.id.listViewWidget, R.id.empty_view);
            remoteView.setRemoteAdapter(appWidgetId, R.id.listViewWidget, widgetServiceIntent);
            remoteView.setTextViewText(R.id.tv_total, context.getString(R.string.today_expenses_total, Util.getFormattedCurrency(Expense.getTotalExpensesByDateMode(IDateMode.MODE_TODAY))));
            remoteView.setPendingIntentTemplate(R.id.listViewWidget, itemClickPendingIntent);
            ComponentName component=new ComponentName(context, ExpensesWidgetProvider.class);
            appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.listViewWidget);
            appWidgetManager.updateAppWidget(component, remoteView);
        }
    }
 
Example #30
Source File: CharacterActivity.java    From Villains-and-Heroes with Apache License 2.0 5 votes vote down vote up
public static PendingIntent getPendingIntent(@NonNull Context context, @NonNull CharacterVO character, int id) {

        Intent intent = new Intent(context, CharacterActivity.class);
        intent.setAction(Integer.toString(id)); // Used to update all PendingIntent extras data for each widget
        intent.putExtra(EXTRA_CHARACTER, character);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addNextIntentWithParentStack(intent); // Return to MainActivity

        return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    }