Example usage for android.net Uri fromFile

List of usage examples for android.net Uri fromFile

Introduction

In this page you can find the example usage for android.net Uri fromFile.

Prototype

public static Uri fromFile(File file) 

Source Link

Document

Creates a Uri from a file.

Usage

From source file:Main.java

public static boolean install(Context context, File file) {
    if (file == null || !file.exists() || !file.isFile()) {
        return false;
    }/*from   w ww  .j  av  a  2  s .c  o  m*/
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
    return true;
}

From source file:Main.java

public static Uri getOutputMediaFileUri(int type, Context c) {
    return Uri.fromFile(getOutputMediaFile(type, c));
}

From source file:Main.java

public static void installApp(Context context, File apkFile) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");

    context.startActivity(intent);//from w  w  w. j  ava 2s  .com
    // YxCfgManager.getYxCfgInstance().write(YxAppCfg.IS_FIRST, true);
}

From source file:Main.java

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

From source file:Main.java

public static void installApk(Context context, File file) {
    Intent intent = new Intent();
    intent.addFlags(268435456);//from   w  ww . j  a v  a2  s  . c  o m
    intent.setAction("android.intent.action.VIEW");
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);
}

From source file:Main.java

public static void addNewImageToGallery(Context context, String filePath) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(filePath);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    context.sendBroadcast(mediaScanIntent);
}

From source file:Main.java

public static Uri getOutputMediaFileUri() {
    return Uri.fromFile(getOutputMediaFile());
}

From source file:Main.java

public static void openPDF(Context context, String path) {
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Uri uri = Uri.fromFile(new File(path));
    intent.setDataAndType(uri, "application/pdf");
    try {//from  w w w.  j a  va 2 s  .c om
        context.startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void installApk(Context context, File file) {
    if (!file.exists()) {
        return;//from ww  w.jav a  2  s . co  m
    }
    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

/**
 * Deprecated, use {@link norg.javiki.IntentBuilder.buildAppInstallIntent} instead
 * @param filePath/*from  w w w .  j av  a2s .c  o  m*/
 * @return
 */
@Deprecated
public static Intent buildAppInstallIntent(File filePath) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(filePath), "application/vnd.android.package-archive");
    return intent;
}