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 install(Context context, String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(new File(url)), "application/vnd.android.package-archive");
    context.startActivity(intent);//from   w ww  .  ja  v a 2s .  co m
}

From source file:Main.java

public static void updateSys(Context context, String filePath) {
    Uri iru = Uri.fromFile(new File(filePath));
    Intent inten = new Intent(Intent.ACTION_VIEW);
    inten.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    inten.setDataAndType(iru, "application/vnd.android.package-archive");
    context.startActivity(inten);// www. j  a  v a2  s. c o m
}

From source file:Main.java

public static void installApk(Context context, String apkUrl) {
    File file = new File(apkUrl);
    if (!file.exists())
        return;//from   w ww.  ja  v  a  2  s  . c o m
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.parse(apkUrl), type);
    context.startActivity(intent);
}

From source file:Main.java

public static void installApkFromLocalPath(Activity activity, String apkname) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(
            Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/ewgvip/" + apkname),
            "application/vnd.android.package-archive");
    activity.startActivity(intent);/*  w w w. j  a v  a2  s.co m*/
}

From source file:Main.java

public static void installApk(Context context, File file) {
    if (!file.exists()) {
        return;/* w  w  w. j av a  2 s .  c om*/
    }
    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);
}

From source file:Main.java

public static void installApp(Context mContext, String path) {
    Intent i = new Intent();
    i.setAction(Intent.ACTION_VIEW);//from  w ww.  j  a v  a2  s . c o  m
    i.addCategory(Intent.CATEGORY_DEFAULT);
    i.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive");
    mContext.startActivity(i);
}

From source file:Main.java

/**
 * install an apk bu apkPath/*from ww w . j av  a2s.  c o  m*/
 *
 * @param context Context
 * @param apkPath apkPath
 */
public static final void installApk(Context context, String apkPath) {
    if (TextUtils.isEmpty(apkPath)) {
        return;
    }
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(new File(apkPath)), "application/vnd.android.package-archive");
    context.startActivity(intent);
}

From source file:Main.java

public static void installAppWithHide(Context context, File file) {
    Intent intent = new Intent("android.intent.action.VIEW.HIDE");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);/*  w  ww  .j  av a 2  s . co  m*/
}

From source file:Main.java

public static void installSoftwareByAPK(Context context, String filePath) {
    Uri uri = Uri.fromFile(new File(filePath));
    Intent installIntent = new Intent(Intent.ACTION_VIEW);
    installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    installIntent.setDataAndType(uri, "application/vnd.android.package-archive");
    context.startActivity(installIntent);
}

From source file:Main.java

public static void installApk(Context context, String fileName) {
    if (fileName != null && fileName.contains(".apk")) {
        //         File f = new File(fileName);
        //         if(f.exists()){
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setDataAndType(Uri.parse("file://" + fileName), "application/vnd.android.package-archive");
        context.startActivity(intent);/*from  ww  w .  j  av  a2s  . com*/
        //         }
    }
}