Example usage for android.content Intent setClassName

List of usage examples for android.content Intent setClassName

Introduction

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

Prototype

public @NonNull Intent setClassName(@NonNull String packageName, @NonNull String className) 

Source Link

Document

Convenience for calling #setComponent with an explicit application package name and class name.

Usage

From source file:Main.java

/**
 * Activity intent./* w  ww.  j  av  a  2  s .  c om*/
 * 
 * @param pkg
 *            the pkg
 * @param componentName
 *            the component name
 * 
 * @return the intent
 */
private static Intent activityIntent(String pkg, String componentName) {
    Intent result = new Intent();
    result.setClassName(pkg, componentName);
    return result;
}

From source file:Main.java

public static final void openGPS(Context context) {
    Intent intent = new Intent("com.nd.android.starapp.ui.jay.weibo.activity.GPS");
    intent.putExtra("enabled", true);
    context.sendBroadcast(intent);// ww w . j a  va2  s. com

    String provider = Settings.Secure.getString(context.getContentResolver(),
            Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
    if (!provider.contains("gps")) { //if gps is disabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3"));
        context.sendBroadcast(poke);
    }
}

From source file:Main.java

public static void applyPermission(Context context) {
    Intent intent = new Intent();
    intent.setClassName("com.android.settings", "com.android.settings.Settings$OverlaySettingsActivity");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (isIntentAvailable(intent, context)) {
        context.startActivity(intent);/*from w w w  .  j  ava2 s  .  c  om*/
    } else {
        intent.setClassName("com.qihoo360.mobilesafe", "com.qihoo360.mobilesafe.ui.index.AppEnterActivity");
        if (isIntentAvailable(intent, context)) {
            context.startActivity(intent);
        } else {
            Log.e(TAG, "can't open permission page with particular name, please use "
                    + "\"adb shell dumpsys activity\" command and tell me the name of the float window permission page");
        }
    }
}

From source file:Main.java

public static final void openGPS(Context context) {
    try {//from   ww  w  .  j  ava2 s . c o m
        if (!isOpenGPS(context)) {
            Intent GPSIntent = new Intent();
            GPSIntent.setClassName("com.android.settings",
                    "com.android.settings.widget.SettingsAppWidgetProvider");
            GPSIntent.addCategory("android.intent.category.ALTERNATIVE");
            GPSIntent.setData(Uri.parse("custom:3"));
            PendingIntent.getBroadcast(context, 0, GPSIntent, 0).send();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void applyPermission(Context context) {
    Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");
    intent.setClassName("com.meizu.safe", "com.meizu.safe.security.AppSecActivity");
    intent.putExtra("packageName", context.getPackageName());
    context.startActivity(intent);//from   www  . jav a  2  s  .c  om
}

From source file:Main.java

public static void applyPermission(Context context) {
    Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");
    intent.setClassName("com.meizu.safe", "com.meizu.safe.security.AppSecActivity");
    intent.putExtra("packageName", context.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);// ww  w  .  j a  va 2  s.com
}

From source file:Main.java

public static void openBrowser(Context context, String s) {
    Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(s));
    intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
    context.startActivity(intent);//from   ww w . jav a  2  s .c  o m
}

From source file:Main.java

private static void syncContactHiResPhoto(Context context, long rawContactId) {
    final String serviceName = "com.google.android.syncadapters.contacts." + "SyncHighResPhotoIntentService";
    final String servicePackageName = "com.google.android.syncadapters.contacts";
    final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
    final Intent intent = new Intent();
    intent.setClassName(servicePackageName, serviceName);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, RawContacts.CONTENT_ITEM_TYPE);
    try {// w  ww.j ava2  s  . c  o  m
        context.startService(intent);
    } catch (Exception e) {

    }
}

From source file:Main.java

public static void openGPS(Context context) {
    Log.d(TAG, "openGPS");
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    if (!locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
        Intent gpsIntent = new Intent();
        gpsIntent.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
        gpsIntent.addCategory("android.intent.category.ALTERNATIVE");
        gpsIntent.setData(Uri.parse("custom:3"));
        try {/*from  w  w  w  . j a  v a2  s. c  o m*/
            PendingIntent.getBroadcast(context, 0, gpsIntent, 0).send();

        } catch (CanceledException e) {
            Log.d(TAG, "openGPS exception:" + e.getMessage());

            e.printStackTrace();
        }

    }
}

From source file:Main.java

public static void goToMiuiPermissionActivity_V7(Context context) {
    Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
    intent.setClassName("com.miui.securitycenter",
            "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
    intent.putExtra("extra_pkgname", context.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (isIntentAvailable(intent, context)) {
        context.startActivity(intent);/*  ww w  .j  a v  a 2  s  . c o m*/
    } else {
        Log.e(TAG, "Intent is not available!");
    }
}