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

/**
 * This method is used for opening any activity from another application. In this case we must ensure that
 * the desired activity is set to "exported". Such as in manifest file:
 *
 * <activity/* ww w  . j  a  va2  s .com*/
 *     android:name=".activity.DesiredActivity"
 *     android:exported="true"
 *     android:screenOrientation="portrait">
 * </activity>
 *
 *
 *
 * @param context                                The context of the activity.
 * @param desiredPackageName                     The package name of the desired or another application.
 * @param desiredActivityNameWithFullPackageName The full path of the activity. Such as : com.example.activity.DesiredActivity
 */
public static void launchActivityFromAnotherApp(Context context, String desiredPackageName,
        String desiredActivityNameWithFullPackageName) {
    Intent intent = new Intent();
    intent.setComponent(new ComponentName(desiredPackageName, desiredActivityNameWithFullPackageName));
    context.startActivity(intent);
}

From source file:Main.java

public static Intent actionGetCreateAccountIntent(final Context context, final String accountManagerType) {
    final Intent i = new Intent();
    i.setComponent(new ComponentName(context, "com.android.email.activity.setup.AccountSetupFinal"));
    i.putExtra(EXTRA_FLOW_MODE, FLOW_MODE_ACCOUNT_MANAGER);
    i.putExtra(EXTRA_FLOW_ACCOUNT_TYPE, accountManagerType);
    return i;/*from  ww w.  j av  a  2  s . com*/
}

From source file:Main.java

public static String getServiceMetaData(Context context, Class<?> serviceClass, String key) {
    String data = null;/*from   w w w  .j  a v a  2s  .com*/
    ServiceInfo info = null;
    try {
        info = context.getPackageManager().getServiceInfo(new ComponentName(context, serviceClass),
                PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    if (info != null) {
        data = info.metaData.get(key).toString();
    }
    return data;
}

From source file:Main.java

public static String getReceiverMetaData(Context context, Class<?> receiverClass, String key) {
    String data = null;/*  www  .j  ava2  s.  c o  m*/
    ActivityInfo info = null;
    try {
        info = context.getPackageManager().getReceiverInfo(new ComponentName(context, receiverClass),
                PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    if (info != null) {
        data = info.metaData.get(key).toString();
    }
    return data;
}

From source file:Main.java

public static void setComponentEnabled(Context ctx, Class<? extends Context> component, boolean enabled) {
    PackageManager pm = ctx.getPackageManager();
    ComponentName componentName = new ComponentName(ctx, component);
    int state = enabled ? COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DISABLED;
    pm.setComponentEnabledSetting(componentName, state, DONT_KILL_APP);
}

From source file:Main.java

public static void runApp(Context context, String paramString) {
    PackageManager localPackageManager = context.getPackageManager();
    try {//from ww  w.jav a  2s .c o  m
        PackageInfo localPackageInfo = localPackageManager.getPackageInfo(paramString, 0);
        Intent localIntent1 = new Intent("android.intent.action.MAIN", null);
        localIntent1.setPackage(localPackageInfo.packageName);
        ResolveInfo localResolveInfo = (ResolveInfo) localPackageManager.queryIntentActivities(localIntent1, 0)
                .iterator().next();
        if (localResolveInfo != null) {
            String str1 = localResolveInfo.activityInfo.packageName;
            String str2 = localResolveInfo.activityInfo.name;
            Intent localIntent2 = new Intent("android.intent.action.MAIN");
            localIntent2.setComponent(new ComponentName(str1, str2));
            context.startActivity(localIntent2);
        }
    } catch (PackageManager.NameNotFoundException localNameNotFoundException) {
        localNameNotFoundException.printStackTrace();
    }
}

From source file:Main.java

/**
 * Restituisce le informazioni relative al package
 * @param context/* www . ja  v a 2  s  . c  o  m*/
 * @param thisClass
 * @return
 */
public static PackageInfo getAppPackageInfo(Context context, Class<?> thisClass) {
    PackageInfo pinfo = null;
    try {
        ComponentName comp = new ComponentName(context, thisClass);
        pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);
    } catch (Exception e) {
    }
    return pinfo;
}

From source file:Main.java

public static String getAppVersion(Context c, @SuppressWarnings("rawtypes") Class cls) {
    try {/*  w  ww.j  a va  2  s  . c  om*/
        ComponentName comp = new ComponentName(c, cls);
        PackageInfo pinfo = c.getPackageManager().getPackageInfo(comp.getPackageName(), 0);
        return pinfo.versionName;
    } catch (android.content.pm.PackageManager.NameNotFoundException e) {
        return null;
    }
}

From source file:Main.java

public static Intent getDefaultAlarmsIntent(Context context) {
    // TODO: consider using AlarmClock.ACTION_SET_ALARM, although it requires a permission
    PackageManager pm = context.getPackageManager();
    for (String packageName : CLOCK_PACKAGES) {
        try {/*  w  ww  .  jav a 2  s  . com*/
            ComponentName cn = new ComponentName(packageName, "com.android.deskclock.AlarmClock");
            pm.getActivityInfo(cn, 0);
            return Intent.makeMainActivity(cn);
        } catch (PackageManager.NameNotFoundException ignored) {
        }
    }
    return getDefaultClockIntent(context);
}

From source file:Main.java

public static String getVoiceSearchIMId(Context context) {
    ComponentName voiceInputComponent = new ComponentName("com.google.android.voicesearch",
            "com.google.android.voicesearch.ime.VoceInputMethdServce");
    if (DEBUG)/*from w  w  w  .  j  ava 2s. c  om*/
        Log.i(TAG, "getVoiceSearchIMId(), Comonent name = " + voiceInputComponent.flattenToString() + ", id = "
                + voiceInputComponent.flattenToShortString());
    return voiceInputComponent.flattenToShortString();
}