Example usage for android.content Intent setAction

List of usage examples for android.content Intent setAction

Introduction

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

Prototype

public @NonNull Intent setAction(@Nullable String action) 

Source Link

Document

Set the general action to be performed.

Usage

From source file:Main.java

public static void sendBroadcast(Context context, String filter, String name, String value) {
    Intent intent = new Intent();
    intent.putExtra(name, value);/*from www .  j  a v  a2s. com*/
    intent.setAction(filter);
    if (mLocalBroadcastManager == null) {
        getLocalBroadcastManager(context.getApplicationContext());
    }
    mLocalBroadcastManager.sendBroadcast(intent);
}

From source file:Main.java

public static void sendBroadcast(Context context, String filter, String name, long value) {
    Intent intent = new Intent();
    intent.putExtra(name, value);//from www  .  j  a v  a  2  s .c o m
    intent.setAction(filter);
    if (mLocalBroadcastManager == null) {
        getLocalBroadcastManager(context.getApplicationContext());
    }
    mLocalBroadcastManager.sendBroadcast(intent);
}

From source file:Main.java

public static void sendBroadcast(Context context, String filter, String name, int value) {
    Intent intent = new Intent();
    intent.putExtra(name, value);//w  w  w  .  j a va  2  s.co m
    intent.setAction(filter);
    if (mLocalBroadcastManager == null) {
        getLocalBroadcastManager(context.getApplicationContext());
    }
    mLocalBroadcastManager.sendBroadcast(intent);
}

From source file:Main.java

public static void sendBroadcast(Context context, String filter, String name, String value, String name1,
        String value1) {/*  w w  w .ja  v a 2 s. c  o m*/
    Intent intent = new Intent();
    intent.putExtra(name, value);
    intent.putExtra(name1, value1);
    intent.setAction(filter);
    context.sendBroadcast(intent);
}

From source file:Main.java

public static void startMobileDataSettingActivity(Context context) {
    Intent mIntent = new Intent("/");
    ComponentName comp = new ComponentName("com.android.phone", "com.android.phone.Settings");
    mIntent.setComponent(comp);/*from   w w  w  .  j  a  v  a  2  s  . c om*/
    mIntent.setAction("android.intent.action.VIEW");
    context.startActivity(mIntent);
}

From source file:Main.java

public static Intent getApplicationDetailsIntent(String packageName) {

    Intent intent = new Intent();
    final int apiLevel = Build.VERSION.SDK_INT;

    if (apiLevel >= 9) { // above 2.3
        intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
        Uri uri = Uri.fromParts(SCHEME, packageName, null);
        intent.setData(uri);/*from  www. ja v  a2 s. c  o m*/
    } else { // below 2.3
        final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22 : APP_PKG_NAME_21);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName(APP_DETAILS_PACKAGE_NAME, APP_DETAILS_CLASS_NAME);
        intent.putExtra(appPkgName, packageName);
    }
    return intent;
}

From source file:Main.java

/**
 * Goes through all apps that handle VIEW intents and have a warmup service. Picks
 * the one chosen by the user if there is one, otherwise makes a best effort to return a
 * valid package name.//from  w  w w .  j  ava  2  s  .c  o m
 *
 * This is <strong>not</strong> threadsafe.
 *
 * @param context {@link Context} to use for accessing {@link PackageManager}.
 * @return The package name recommended to use for connecting to custom tabs related components.
 */
public static String getPackageNameToUse(Context context) {
    if (sPackageNameToUse != null)
        return sPackageNameToUse;

    PackageManager pm = context.getPackageManager();
    // Get default VIEW intent handler.
    Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
    String defaultViewHandlerPackageName = null;
    if (defaultViewHandlerInfo != null) {
        defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
    }

    // Get all apps that can handle VIEW intents.
    List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
    List<String> packagesSupportingCustomTabs = new ArrayList<>();
    for (ResolveInfo info : resolvedActivityList) {
        Intent serviceIntent = new Intent();
        serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
        serviceIntent.setPackage(info.activityInfo.packageName);
        if (pm.resolveService(serviceIntent, 0) != null) {
            packagesSupportingCustomTabs.add(info.activityInfo.packageName);
        }
    }

    // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
    // and service calls.
    if (packagesSupportingCustomTabs.isEmpty()) {
        sPackageNameToUse = null;
    } else if (packagesSupportingCustomTabs.size() == 1) {
        sPackageNameToUse = packagesSupportingCustomTabs.get(0);
    } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName)
            && !hasSpecializedHandlerIntents(context, activityIntent)
            && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) {
        sPackageNameToUse = defaultViewHandlerPackageName;
    } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) {
        sPackageNameToUse = STABLE_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) {
        sPackageNameToUse = BETA_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) {
        sPackageNameToUse = DEV_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
        sPackageNameToUse = LOCAL_PACKAGE;
    }
    return sPackageNameToUse;
}

From source file:Main.java

public static void sendBroadcast(Context context, String filter, String name, Serializable serializable) {
    Intent intent = new Intent();
    intent.putExtra(name, serializable);
    intent.setAction(filter);
    if (mLocalBroadcastManager == null) {
        getLocalBroadcastManager(context.getApplicationContext());
    }//from ww w  . ja v  a2s . com
    mLocalBroadcastManager.sendBroadcast(intent);
}

From source file:Main.java

public static void goToInstalledAppDetails(Context context, String packageName) {
    Intent intent = new Intent();
    int sdkVersion = Build.VERSION.SDK_INT;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.fromParts("package", packageName, null));
    } else {/* w ww .j ava 2 s .  c o m*/
        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
        intent.putExtra(
                (sdkVersion == Build.VERSION_CODES.FROYO ? "pkg" : "com.android.settings.ApplicationPkgName"),
                packageName);
    }
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:Main.java

public static void openSetting(Activity activity, int requestCode) {
    Intent intent = new Intent("/");
    ComponentName cm = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");
    intent.setComponent(cm);/*from   www  .  j  a v  a2s. c  o m*/
    intent.setAction(Intent.ACTION_VIEW);
    activity.startActivityForResult(intent, requestCode);
}