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

/** Create a file Uri for saving an image or video */
public static Uri getOutputMediaFileUri(int type, String optionalAppName) {
    return Uri.fromFile(getOutputMediaFile(type, optionalAppName));
}

From source file:Main.java

public static void installApp(Context context, File file) {
    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);// ww w.  jav a  2  s.c om
}

From source file:Main.java

public static void inistallSoftware(Context context, String packageName) {
    String fileName = Environment.getExternalStorageDirectory() + "/" + packageName;
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
    context.startActivity(intent);/* w w w  .  j a  va  2 s .c om*/
}

From source file:Main.java

/***
 * Constructs an intent for capturing a photo and storing it in a temporary
 * file.// www  .j  a  va 2s.c om
 */
public static Intent getTakePickIntent(File f) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
    return intent;
}

From source file:Main.java

public static void share(Context context, String imageFileLocation, String textToSend) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/*");

    intent.putExtra(Intent.EXTRA_TEXT, textToSend);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imageFileLocation)));

    context.startActivity(Intent.createChooser(intent, "Share with..."));
}

From source file:Main.java

public static Pair<Boolean, Uri> isTrackExist(Context context, String artist, String track) {
    File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_MUSIC),
            artist + " - " + track + ".mp3");
    return new Pair<>(file.exists(), Uri.fromFile(file));
}

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(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);//  www.j av a2 s  .  com
}

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);/*from w  w w.  ja  v a2s . com*/
    }
}

From source file:Main.java

public static Uri getOutputMediaFileUri(Context context) {
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    return Uri.fromFile(getOutputMediaFile(context, "IMG_" + timeStamp + ".jpg"));
}

From source file:Main.java

public static void installAPK(Context context, File file) {
    if (file == null || !file.exists())
        return;/*from  w  ww. j  a  v  a2s .  c o m*/
    Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);
}