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 openNetworkSetting(Activity activity) {
    Intent intent = new Intent("/");
    ComponentName cm = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");
    intent.setComponent(cm);/*from  w  w  w  .j  a v  a  2  s . com*/
    intent.setAction("android.intent.action.VIEW");
    activity.startActivityForResult(intent, 0);
}

From source file:Main.java

public static void openSetting(Activity activity) {
    Intent intent = new Intent("/");
    ComponentName cm = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");
    intent.setComponent(cm);//from  www . j a  v a2  s . c  o m
    intent.setAction("android.intent.action.VIEW");
    activity.startActivityForResult(intent, 0);
}

From source file:Main.java

public static void openNet(Activity activity) {
    Intent intent = new Intent("/");
    ComponentName cm = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");
    intent.setComponent(cm);//from   w  ww  .  ja  va  2 s  .co  m
    intent.setAction("android.intent.action.VIEW");
    activity.startActivityForResult(intent, 0);
}

From source file:Main.java

public static void openNetSetting(Activity act) {
    Intent intent = new Intent();
    ComponentName cm = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");
    intent.setComponent(cm);//from   ww  w .  ja v a  2s.c o  m
    intent.setAction("android.intent.action.VIEW");
    act.startActivityForResult(intent, 0);
}

From source file:Main.java

public static void chooserPics(Context context, int requestCode) {
    if (context == null) {
        return;//w ww.  j a  va2 s .  c o  m
    }

    try {
        Intent localIntent = new Intent();
        localIntent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        localIntent.setType("image/*");
        localIntent.setAction(Intent.ACTION_GET_CONTENT);
        if (context instanceof Activity) {
            ((Activity) context).startActivityForResult(Intent.createChooser(localIntent, "Select Picture"),
                    requestCode);
        } else {
            localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(Intent.createChooser(localIntent, "Select Picture"));
        }
    } catch (Exception e) {
    }
}

From source file:com.elkriefy.android.apps.chubbytabby.CustomTabsHelper.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 .  jav a2s  .  c  om
 *
 * 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("https://www.packtpub.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(CustomTabsService.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 (!android.text.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:com.samknows.measurement.util.LoginHelper.java

public static void logout(Activity parent) {
    parent.startActivity(new Intent(parent, SamKnowsLogin.class));

    AppSettings.getInstance().clearAll();
    AppSettings.getInstance().setServiceActivated(false);
    CachingStorage.getInstance().dropExecutionQueue();
    CachingStorage.getInstance().dropParamsManager();

    Intent broadcastIntent = new Intent();
    broadcastIntent.setAction(Constants.INTENT_ACTION_LOGOUT);
    parent.sendBroadcast(broadcastIntent);
}

From source file:mohammad.adib.oy.OyUtils.java

public static void sendInvite(Context context) {
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT,
            "Oy! Wanna fraandship?\nSend me an Oy: " + ParseUser.getCurrentUser().getUsername().toUpperCase());
    sendIntent.setType("text/plain");
    context.startActivity(sendIntent);/*from ww w.  ja v  a2  s  .co  m*/
}

From source file:com.arellomobile.android.push.PushGCMIntentService.java

private static void generateBroadcast(Context context, Bundle extras) {
    Intent broadcastIntent = new Intent();
    broadcastIntent.setAction(context.getPackageName() + ".action.PUSH_MESSAGE_RECEIVE");
    broadcastIntent.putExtras(extras);//w  w w .j a va 2  s  . c o m

    JSONObject dataObject = new JSONObject();
    try {
        if (extras.containsKey("title")) {
            dataObject.put("title", extras.get("title"));
        }
        if (extras.containsKey("u")) {
            dataObject.put("userdata", new JSONObject(extras.getString("u")));
        }
    } catch (JSONException e) {
        // pass
    }

    broadcastIntent.putExtra(BasePushMessageReceiver.DATA_KEY, dataObject.toString());

    context.sendBroadcast(broadcastIntent, context.getPackageName() + ".permission.C2D_MESSAGE");
}

From source file:Main.java

public static void sendBroadcast(Context context, String filter, String name, String value, String name1,
        String value1) {//from ww w.jav a 2 s  .  com
    Intent intent = new Intent();
    intent.putExtra(name, value);
    intent.putExtra(name1, value1);
    intent.setAction(filter);
    if (mLocalBroadcastManager == null) {
        getLocalBroadcastManager(context.getApplicationContext());
    }
    mLocalBroadcastManager.sendBroadcast(intent);
}