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 void toggleComponent(Context context, Class componentClass, boolean state) {
    ComponentName componentName = new ComponentName(context, componentClass);
    context.getPackageManager().setComponentEnabledSetting(componentName,
            state ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:Main.java

public static void intentSetting(Context context) {
    String pkg = "com.android.settings";
    String cls = "com.android.settings.Settings";

    ComponentName component = new ComponentName(pkg, cls);
    Intent intent = new Intent();
    intent.setComponent(component);//from  w w w  .ja  v  a  2 s .  com

    context.startActivity(intent);
}

From source file:Main.java

public static void startComponent(Context context, String packageName, String className) {
    Intent intent = new Intent();
    ComponentName component = new ComponentName(packageName, className);
    intent.setComponent(component);/*from   w ww. j  a v  a2  s  .c  om*/
    if (intent != null) {
        context.startActivity(intent);
    }
}

From source file:Main.java

public static void startPackage(Activity activity, String s, String s1, Bundle bundle) {
    Intent intent = new Intent();
    intent.setComponent(new ComponentName(s, s1));
    intent.putExtras(bundle);//from w  w  w. j a  v a  2 s.  com
    activity.startActivity(intent);
}

From source file:Main.java

public static String getServiceMetaData(Context context, Class<? extends Service> serviceClazz, String key) {
    try {/*from  w  w w .ja v  a 2  s .c  om*/
        return context.getPackageManager().getServiceInfo(new ComponentName(context, serviceClazz),
                PackageManager.GET_META_DATA).metaData.getString(key);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static boolean isExsistServices(Context context, Class<?> mClass) throws NameNotFoundException {
    return context.getPackageManager().getServiceInfo(new ComponentName(context, mClass),
            PackageManager.GET_META_DATA) != null;
}

From source file:Main.java

private static Intent getComponentIntent(String packageName, String className, Bundle bundle) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    if (bundle != null)
        intent.putExtras(bundle);// w w w  .j  a v  a  2s .  c o  m
    ComponentName cn = new ComponentName(packageName, className);
    intent.setComponent(cn);
    return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}

From source file:Main.java

public static void setHideApplication(Context c, boolean hide) {
    ComponentName cn = new ComponentName(c.getApplicationContext(), ALIAS_CLASSNAME);
    int setting = hide ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
            : PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    int current = c.getPackageManager().getComponentEnabledSetting(cn);
    if (current != setting) {
        c.getPackageManager().setComponentEnabledSetting(cn, setting, PackageManager.DONT_KILL_APP);
    }/*ww  w. j  a  va 2s .co m*/
}

From source file:Main.java

public static String getVersion(Context context) {
    String version = "";
    // get current version
    try {//w w w.  ja  v  a  2s.co m
        ComponentName comp = new ComponentName(context, "");
        PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);
        version = pinfo.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return version;
}

From source file:Main.java

public static String getAppVersion(Context context) {
    String version = "";
    // get current version
    try {//  w ww  .  j  a va2  s  . c  o m
        ComponentName comp = new ComponentName(context, "");
        PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);
        version = pinfo.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return version;
}