Java Code Examples for android.content.Intent#makeMainActivity()

The following examples show how to use android.content.Intent#makeMainActivity() . These examples are extracted from open source projects. 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
/**
 * Add the activity parent chain as specified by the
 * {@link android.R.attr#parentActivityName parentActivityName} attribute of the activity
 * (or activity-alias) element in the application's manifest to the task stack builder.
 *
 * @param sourceActivityName Must specify an Activity component. All parents of
 *                           this activity will be added
 * @return This TaskStackBuilder for method chaining
 */
public TaskStackBuilder addParentStack(ComponentName sourceActivityName) {
    final int insertAt = mIntents.size();
    PackageManager pm = mSourceContext.getPackageManager();
    try {
        ActivityInfo info = pm.getActivityInfo(sourceActivityName, 0);
        String parentActivity = info.parentActivityName;
        while (parentActivity != null) {
            final ComponentName target = new ComponentName(info.packageName, parentActivity);
            info = pm.getActivityInfo(target, 0);
            parentActivity = info.parentActivityName;
            final Intent parent = parentActivity == null && insertAt == 0
                    ? Intent.makeMainActivity(target)
                    : new Intent().setComponent(target);
            mIntents.add(insertAt, parent);
        }
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Bad ComponentName while traversing activity parent metadata");
        throw new IllegalArgumentException(e);
    }
    return this;
}
 
Example 2
/**
 * Launches an activity based on its component name.
 *
 * @param activity      Current foreground activity.
 * @param componentName Component name of the app to be launched.
 */
static void quickLaunch(Activity activity, String componentName) throws ActivityNotFoundException {
    // When receiving 'none', it's probably a gesture that hasn't been registered.
    if ("none".equals(componentName)) {
        return;
    }

    ComponentName component = ComponentName.unflattenFromString(componentName);

    // Forcibly end if we can't unflatten the string.
    if (component == null) {
        return;
    }

    Intent intent = Intent.makeMainActivity(component);
    intent.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    activity.startActivity(intent);
}
 
Example 3
/**
 * Launches an activity based on its component name.
 *
 * @param activity      Current foreground activity.
 * @param componentName Component name of the app to be launched.
 */
static void quickLaunch(Activity activity, String componentName) throws ActivityNotFoundException {
    // When receiving 'none', it's probably a gesture that hasn't been registered.
    if ("none".equals(componentName)) {
        return;
    }

    ComponentName component = ComponentName.unflattenFromString(componentName);

    // Forcibly end if we can't unflatten the string.
    if (component == null) {
        return;
    }

    Intent intent = Intent.makeMainActivity(component);
    intent.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    activity.startActivity(intent);
}
 
Example 4
private NotificationItem(int id, String title, String desc, String channelId) {
    super(id, title, desc);
    final Intent[] intents = new Intent[2];
    intents[0] = Intent.makeMainActivity(
            new ComponentName(DemoApplication.CONTEXT, MainActivity.class));
    intents[1] = new Intent(DemoApplication.CONTEXT, NotificationSampleActivity.class);
    final PendingIntent pendingIntent = PendingIntent.getActivities(
            DemoApplication.CONTEXT, 0, intents,
            PendingIntent.FLAG_UPDATE_CURRENT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        builder = new NotificationCompat.Builder(
                FileDownloadHelper.getAppContext(),
                channelId);
    } else {
        //noinspection deprecation
        builder = new NotificationCompat.Builder(FileDownloadHelper.getAppContext())
                .setDefaults(Notification.DEFAULT_LIGHTS)
                .setPriority(NotificationCompat.PRIORITY_MIN);
    }

    builder.setContentTitle(getTitle())
            .setContentText(desc)
            .setContentIntent(pendingIntent)
            .setSmallIcon(R.mipmap.ic_launcher);
}
 
Example 5
@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 6
Source Project: VirtualAPK   File: LoadedPlugin.java    License: Apache License 2.0 5 votes vote down vote up
public Intent getLaunchIntent() {
    ContentResolver resolver = this.mPluginContext.getContentResolver();
    Intent launcher = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);

    for (PackageParser.Activity activity : this.mPackage.activities) {
        for (PackageParser.ActivityIntentInfo intentInfo : activity.intents) {
            if (intentInfo.match(resolver, launcher, false, TAG) > 0) {
                return Intent.makeMainActivity(activity.getComponentName());
            }
        }
    }

    return null;
}
 
Example 7
Source Project: android-test   File: ActivityInvoker.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Finds an intent to start an Activity of the given class. It looks up target context first and
 * fallback to instrumentation context.
 */
default Intent getIntentForActivity(Class<? extends Activity> activityClass) {
  Intent intent =
      Intent.makeMainActivity(
          new ComponentName(getInstrumentation().getTargetContext(), activityClass));
  if (getInstrumentation().getTargetContext().getPackageManager().resolveActivity(intent, 0)
      != null) {
    return intent;
  }
  return Intent.makeMainActivity(
      new ComponentName(getInstrumentation().getContext(), activityClass));
}
 
Example 8
public static Intent getDefaultAlarmsIntent(Context context) {
    PackageManager pm = context.getPackageManager();
    for (String packageName : DESK_CLOCK_PACKAGES) {
        try {
            ComponentName cn = new ComponentName(packageName, "com.android.deskclock.AlarmClock");
            pm.getActivityInfo(cn, 0);
            return Intent.makeMainActivity(cn);
        } catch (PackageManager.NameNotFoundException ignored) {
        }
    }
    return getDefaultClockIntent(context);
}
 
Example 9
Source Project: MiBandDecompiled   File: j.java    License: Apache License 2.0 4 votes vote down vote up
public static Intent a(ComponentName componentname)
{
    return Intent.makeMainActivity(componentname);
}
 
Example 10
public static Intent makeMainActivity(ComponentName mainActivity) {
    return Intent.makeMainActivity(mainActivity);
}
 
Example 11
public static Intent makeMainActivity(ComponentName mainActivity) {
    return Intent.makeMainActivity(mainActivity);
}
 
Example 12
Source Project: V.FlyoutTest   File: IntentCompatHoneycomb.java    License: MIT License 4 votes vote down vote up
public static Intent makeMainActivity(ComponentName mainActivity) {
    return Intent.makeMainActivity(mainActivity);
}
 
Example 13
Source Project: guideshow   File: IntentCompatHoneycomb.java    License: MIT License 4 votes vote down vote up
public static Intent makeMainActivity(ComponentName mainActivity) {
    return Intent.makeMainActivity(mainActivity);
}