Example usage for android.content ComponentName ComponentName

List of usage examples for android.content ComponentName ComponentName

Introduction

In this page you can find the example usage for android.content ComponentName ComponentName.

Prototype

private ComponentName(String pkg, Parcel in) 

Source Link

Usage

From source file:Main.java

public static int[] getAppWidgetIds(AppWidgetManager appWidgetManager, Context context, Class<?> clazz) {
    return appWidgetManager.getAppWidgetIds(new ComponentName(context, clazz));
}

From source file:Main.java

public static void startActivity(Context mContext, String packageName, String className) {
    try {// ww w.  j  a  v  a 2 s .c o  m
        ComponentName com = new ComponentName(packageName, className);
        Intent intent = new Intent();
        intent.setComponent(com);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void goProgram(Context context, String pkg, String fullclasspath) {
    Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(new ComponentName(pkg, fullclasspath));
    context.startActivity(intent);/*from w  w  w .  j  av  a  2  s. c o m*/
}

From source file:Main.java

public static void startApkActivity(final Context ctx, String packageName) {
    PackageManager pm = ctx.getPackageManager();
    PackageInfo pi;/*ww  w.jav  a  2  s.c  o m*/
    try {
        pi = pm.getPackageInfo(packageName, 0);
        Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setPackage(pi.packageName);

        List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0);

        ResolveInfo ri = apps.iterator().next();
        if (ri != null) {
            String className = ri.activityInfo.name;
            intent.setComponent(new ComponentName(packageName, className));
            ctx.startActivity(intent);
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void delShortcutFromDesktop(Context paramContext, String packageName, String cls,
        String appName) {/* w ww .  j  a va  2  s.  c o  m*/
    Intent localIntent1 = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
    String str = appName;
    PackageManager localPackageManager = paramContext.getPackageManager();
    int i = 8320;
    try {
        ApplicationInfo localApplicationInfo = localPackageManager.getApplicationInfo(packageName, i);
        if (str == null)
            str = localPackageManager.getApplicationLabel(localApplicationInfo).toString();
        localIntent1.putExtra("android.intent.extra.shortcut.NAME", str);
        ComponentName localComponentName = new ComponentName(packageName, cls);
        Intent localIntent2 = new Intent(Intent.ACTION_MAIN).setComponent(localComponentName);
        localIntent2.addCategory(Intent.CATEGORY_LAUNCHER);
        localIntent1.putExtra("android.intent.extra.shortcut.INTENT", localIntent2);
        paramContext.sendBroadcast(localIntent1);
        return;
    } catch (PackageManager.NameNotFoundException localNameNotFoundException) {
        while (true)
            localNameNotFoundException.printStackTrace();
    }
}

From source file:Main.java

public static Intent actionNewAccountIntent(final Context context) {
    final Intent i = new Intent();
    i.setComponent(new ComponentName(context, "com.android.email.activity.setup.AccountSetupFinal"));
    i.putExtra(EXTRA_FLOW_MODE, FLOW_MODE_NORMAL);
    return i;/*from   w  ww.  ja  v  a 2 s .c om*/
}

From source file:Main.java

public static Intent actionNewAccountWithResultIntent(final Context context) {
    final Intent i = new Intent();
    i.setComponent(new ComponentName(context, "com.android.email.activity.setup.AccountSetupFinal"));
    i.putExtra(EXTRA_FLOW_MODE, FLOW_MODE_NO_ACCOUNTS);
    return i;/* ww w. ja v  a  2 s. c om*/
}

From source file:Main.java

public static void toggleAppIcon(Context context, boolean newState) {
    ComponentName componentName = new ComponentName("com.noshufou.android.su", "com.noshufou.android.su.Su");
    context.getPackageManager().setComponentEnabledSetting(componentName,
            newState ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:Main.java

public static void startApkActivity(final Context ctx, String packageName) {
    PackageManager pm = ctx.getPackageManager();
    PackageInfo pi;/*from  www .j a v a2 s  .  c  o  m*/
    try {
        pi = pm.getPackageInfo(packageName, 0);
        Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setPackage(pi.packageName);

        List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0);

        ResolveInfo ri = apps.iterator().next();
        if (ri != null) {
            String className = ri.activityInfo.name;
            intent.setComponent(new ComponentName(packageName, className));
            ctx.startActivity(intent);
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * @param packageName/* w  w w  .  ja v a  2  s.c om*/
 * @param context
 */
public static void openApp(String packageName, Context context) {

    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);

    resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    resolveIntent.setPackage(packageName);

    List<ResolveInfo> apps = context.getPackageManager().queryIntentActivities(resolveIntent, 0);

    ResolveInfo ri = apps.iterator().next();

    if (ri != null) {

        String packageName_i = ri.activityInfo.packageName;

        String className_i = ri.activityInfo.name;

        Intent intent = new Intent(Intent.ACTION_MAIN);

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        ComponentName cn = new ComponentName(packageName_i, className_i);

        intent.setComponent(cn);

        context.startActivity(intent);

    }

}