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 jumpToActivity(Context context, ComponentName componentName) {
    Intent mIntent = new Intent();
    mIntent.addFlags(268435456);/*ww w. j a v  a 2s .  co  m*/
    mIntent.setComponent(componentName);
    mIntent.setAction("android.intent.action.VIEW");
    context.startActivity(mIntent);
}

From source file:Main.java

public static void shareOnTwitter(Context pContext, String urlToShare) {

    Intent tweetIntent = new Intent(Intent.ACTION_SEND);
    tweetIntent.putExtra(Intent.EXTRA_TEXT, urlToShare);
    tweetIntent.setType("text/plain");

    PackageManager packManager = pContext.getPackageManager();
    List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent,
            PackageManager.MATCH_DEFAULT_ONLY);

    boolean resolved = false;
    for (ResolveInfo resolveInfo : resolvedInfoList) {
        if (resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) {
            tweetIntent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
            resolved = true;//from  w  ww. ja va  2 s  . co m
            break;
        }
    }
    if (resolved) {
        pContext.startActivity(tweetIntent);
    } else {
        Intent i = new Intent();
        i.putExtra(Intent.EXTRA_TEXT, urlToShare);
        i.setAction(Intent.ACTION_VIEW);
        i.setData(Uri.parse("https://twitter.com/intent/tweet?text=message&via=profileName"));
        pContext.startActivity(i);
    }
}

From source file:Main.java

@SuppressLint("InlinedApi")
public static void openSys(Context context, String packageName) {
    Intent intent = new Intent();
    final int apiLevel = Build.VERSION.SDK_INT;
    if (apiLevel >= 9) {
        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.fromParts("package", packageName, null));
    } else {/*from ww w .j  a v a2s . co  m*/
        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
        String appPkgName = (apiLevel == 8 ? "pkg" : "com.android.settings.ApplicationPkgName");
        intent.putExtra(appPkgName, packageName);
    }
    context.startActivity(intent);
}

From source file:Main.java

public static void jumpToActivity(Context context, ComponentName componentName, String... datas) {
    Intent mIntent = new Intent();
    mIntent.addFlags(268435456);/*from  w ww.  jav  a 2 s. co m*/
    mIntent.setComponent(componentName);
    mIntent.setAction("android.intent.action.VIEW");
    if (datas != null) {
        for (int i = 0; i < datas.length; ++i) {
            mIntent.putExtra("data" + i, datas[i]);
        }
    }

    context.startActivity(mIntent);
}

From source file:Main.java

public static Intent getImageFromGalleryCamera(Context context) {
    // Determine Uri of camera image to save.
    File root = new File(
            Environment.getExternalStorageDirectory() + File.separator + "dianta/camera" + File.separator);
    root.mkdirs();/*from  w  w  w.  j  a v  a  2s .  c o m*/
    String fname = "dianta-" + System.currentTimeMillis() + ".jpg";
    File sdImageMainDirectory = new File(root, fname);
    Uri outputFileUri = Uri.fromFile(sdImageMainDirectory);

    // camera
    List<Intent> cameraIntents = new ArrayList<>();
    Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager lPackageManager = context.getPackageManager();
    List<ResolveInfo> listCam = lPackageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo rInfo : listCam) {
        String packageName = rInfo.activityInfo.packageName;
        Intent lIntent = new Intent(captureIntent);
        lIntent.setComponent(new ComponentName(rInfo.activityInfo.packageName, rInfo.activityInfo.name));
        lIntent.setPackage(packageName);
        //save camera result to external storage
        lIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        cameraIntents.add(lIntent);
    }

    //ugly hacks for camera helper
    lastCameraImageSaved = outputFileUri;

    // gallery
    Intent galleryIntent = new Intent();
    galleryIntent.setType("image/*");
    galleryIntent.setAction(Intent.ACTION_PICK);

    Intent chooserIntent = Intent.createChooser(galleryIntent, "Pilih Sumber");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            cameraIntents.toArray(new Parcelable[cameraIntents.size()]));

    return chooserIntent;
}

From source file:Main.java

public static void install(Context context, String apkFilePath) {
    if (context == null) {
        throw new RuntimeException("ApkUtils install apk method and parameter context  == null?");
    }/*from w w w.j av  a2s  . c om*/

    File file = new File(apkFilePath);

    if (!file.exists()) {
        return;
    }

    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);
}

From source file:Main.java

public static Intent share(String text, String mimeType, Uri... attachments) {
    final Intent intent = new Intent();
    intent.setType(mimeType);//from w w  w . ja v  a  2 s . c  om
    if (attachments.length > 1) {
        intent.setAction(Intent.ACTION_SEND_MULTIPLE);
        final ArrayList<CharSequence> textExtra = new ArrayList<>();
        textExtra.add(text);
        intent.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, textExtra);
        final ArrayList<Parcelable> uris = new ArrayList<>();
        Collections.addAll(uris, attachments);
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    } else {
        intent.setAction(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, text);
        intent.putExtra(Intent.EXTRA_STREAM, attachments[0]);
    }
    return intent;
}

From source file:Main.java

public static Intent share(String text, String mimeType, Uri... attachments) {
    final Intent intent = new Intent();
    intent.setType(mimeType);//w  w  w.  j  av  a 2s  . c  o  m
    if (attachments.length > 1) {
        intent.setAction(Intent.ACTION_SEND_MULTIPLE);
        final ArrayList<CharSequence> textExtra = new ArrayList<>();
        textExtra.add(text);
        intent.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, textExtra);
        final ArrayList<Parcelable> uris = new ArrayList<>();
        Collections.addAll(uris, attachments);
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    } else {
        intent.setAction(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, text);
        if (attachments.length > 0) {
            intent.putExtra(Intent.EXTRA_STREAM, attachments[0]);
        }
    }
    return intent;
}

From source file:Main.java

/**
 * Checks if there is any Pay by Bank app enabled CFI App installed on the device.
 *
 * @param context The context to use./*from  w w w.  j a va 2s.  c om*/
 * @return True if there is at least one PBBA enabled CFI App available, false otherwise.
 * @see #openBankingApp(Context, String)
 */
public static boolean isCFIAppAvailable(@NonNull final Context context) {

    //noinspection ConstantConditions
    if (context == null) {
        throw new IllegalArgumentException("context == null");
    }

    final Intent zappIntent = new Intent();
    zappIntent.setData(new Uri.Builder().scheme(ZAPP_SCHEME).build());
    zappIntent.setAction(Intent.ACTION_VIEW);
    final ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(zappIntent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return resolveInfo != null;
}

From source file:Main.java

public static void openSettings(Activity context, String action) {
    Intent intent = new Intent();
    ComponentName comp = new ComponentName("com.android.settings", action);
    intent.setComponent(comp);// w  ww  . j  a  v  a 2  s  . c  o  m
    intent.setAction("android.intent.action.VIEW");
    context.startActivityForResult(intent, 0);
}