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

The following examples show how to use android.content.Intent#makeMainActivity() . 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: TaskStackBuilder.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * 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
Source File: AppUtils.java    From HgLauncher with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
Source File: AppUtils.java    From HgLauncher with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
Source File: NotificationSampleActivity.java    From FileDownloader with Apache License 2.0 6 votes vote down vote up
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
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 6
Source File: LoadedPlugin.java    From VirtualAPK with 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 File: ActivityInvoker.java    From android-test with 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
Source File: Utils.java    From al-muazzin with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 File: j.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public static Intent a(ComponentName componentname)
{
    return Intent.makeMainActivity(componentname);
}
 
Example 10
Source File: IntentCompatHoneycomb.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public static Intent makeMainActivity(ComponentName mainActivity) {
    return Intent.makeMainActivity(mainActivity);
}
 
Example 11
Source File: IntentCompatHoneycomb.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static Intent makeMainActivity(ComponentName mainActivity) {
    return Intent.makeMainActivity(mainActivity);
}
 
Example 12
Source File: IntentCompatHoneycomb.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static Intent makeMainActivity(ComponentName mainActivity) {
    return Intent.makeMainActivity(mainActivity);
}
 
Example 13
Source File: IntentCompatHoneycomb.java    From guideshow with MIT License 4 votes vote down vote up
public static Intent makeMainActivity(ComponentName mainActivity) {
    return Intent.makeMainActivity(mainActivity);
}