Example usage for android.content Intent setDataAndType

List of usage examples for android.content Intent setDataAndType

Introduction

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

Prototype

public @NonNull Intent setDataAndType(@Nullable Uri data, @Nullable String type) 

Source Link

Document

(Usually optional) Set the data for the intent along with an explicit MIME data type.

Usage

From source file:Main.java

public static void showPicture(Context mContext, String imagePath) {
    File file = new File(imagePath);
    if (file != null && file.isFile() == true) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file), "image/*");
        mContext.startActivity(intent);/* www  . j  a va 2 s.  c o  m*/
    }
}

From source file:Main.java

public static Intent getOpenFileIntent(Uri uri, String mimeType) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, mimeType);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    return intent;
}

From source file:Main.java

public static void startInstallAPK(Context context, String path) {
    try {/*from  ww  w .j a  v  a2 s . c  om*/
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive");
        context.startActivity(intent);
    } catch (Exception e) {

    }
}

From source file:Main.java

public static void cropImgFromSelfCenter(Uri uri) {
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, "image/*");
    intent.putExtra("crop", "true");
    intent.putExtra("aspectX", 110);
    intent.putExtra("aspectY", 135);
    intent.putExtra("outputX", 110);
    intent.putExtra("outputY", 135);
    intent.putExtra("return-data", false);
    intent.putExtra("noFaceDetection", true);
    File mFile = new File(Environment.getExternalStorageDirectory() + "/yourName");
    if (!mFile.exists())
        mFile.mkdirs();/*from  w  w  w  . ja  va 2 s. c o  m*/
    mCropAvatar = new File(CROP_IMG_PATH);
    if (mCropAvatar.exists())
        mCropAvatar.delete();
    mCropUri = Uri.fromFile(mCropAvatar);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mCropUri);
    mActivity.startActivityForResult(intent, REQUEST_CROP_RETURN_SELF_CENTER);
}

From source file:Main.java

public static void startInstall(final Context context, String fileName) {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse("file://" + getSdcardFileName(fileName)),
            "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);//from  www  . j a  va 2s  . c o m
}

From source file:Main.java

public static void install(Context context, String filePath) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(new File(filePath)), "application/vnd.android.package-archive");
    context.startActivity(intent);//from   w  ww . ja  v a 2s  .  c o  m
}

From source file:Main.java

public static void installApp(Context context, File file) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);//from   w w  w . ja  v  a 2s . c om
}

From source file:Main.java

public static void installApp(Context context, String path) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.parse("file://" + path), "application/vnd.android.package-archive");
    context.startActivity(intent);//from   w w  w  .j a va 2  s.  co  m
}

From source file:Main.java

public static void installApk(Context context, File file) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);/*  w  w  w .j a va2 s.  c  o m*/
}

From source file:Main.java

public static void installApp(Context context, File apkFile) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
    context.startActivity(intent);/*from   w w  w . j av a  2 s  .c  om*/
}