Java Code Examples for android.net.Uri.fromFile()

The following are Jave code examples for showing how to use fromFile() of the android.net.Uri class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: haven   File: EventActivity.java   View Source Code Vote up 7 votes
private void shareEvent ()
{
    String title = "Phoneypot: " + mEvent.getStartTime().toLocaleString();

    //need to "send multiple" to get more than one attachment
    final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("text/plain");

    emailIntent.putExtra(Intent.EXTRA_SUBJECT, title);
    emailIntent.putExtra(Intent.EXTRA_TEXT, generateLog());
    //has to be an ArrayList
    ArrayList<Uri> uris = new ArrayList<>();
    //convert from paths to Android friendly Parcelable Uri's
    for (EventTrigger trigger : mEvent.getEventTriggers())
    {
        File fileIn = new File(trigger.getPath());
        Uri u = Uri.fromFile(fileIn);
        uris.add(u);
    }

    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    startActivity(Intent.createChooser(emailIntent, getString(R.string.share_event_action)));
}
 
Example 2
Project: simple-share-android   File: FileUtils.java   View Source Code Vote up 7 votes
public static void updateMediaStore(Context context, ArrayList<DocumentInfo> docs, String parentPath) {
    try {
        if(Utils.hasKitKat()){
            ArrayList<String> paths = new ArrayList<>();
            for(DocumentInfo doc : docs){
                paths.add(parentPath + File.separator + doc.displayName);
            }
            String[] pathsArray = paths.toArray(new String[paths.size()]);
            FileUtils.updateMediaStore(context, pathsArray);
        }
        else{
            Uri contentUri = Uri.fromFile(new File(parentPath).getParentFile());
            Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, contentUri);
            context.sendBroadcast(mediaScanIntent);
        }
    }
    catch (Exception e){
        e.printStackTrace();
    }
}
 
Example 3
Project: BaseCore   File: LocalShareUtils.java   View Source Code Vote up 6 votes
/**
 * 分享单张图片至所有第三方软件
 */
public static void ShareSingleImage(Context context, File file) {
    Uri imageUri;

    if (Build.VERSION.SDK_INT >= 24) {
        imageUri = FileProvider.getUriForFile(context,"com.hzecool.common.fileProvider", file);
    } else {
        imageUri = Uri.fromFile(file);
    }


    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
    shareIntent.setType("image/*");
    context.startActivity(Intent.createChooser(shareIntent, "分享到"));

}
 
Example 4
Project: Android-Music-Player   File: folderAdapter.java   View Source Code Vote up 6 votes
void  getSongsFiles(String Name){
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND_MULTIPLE);
    intent.putExtra(Intent.EXTRA_SUBJECT, "All Songs from this Albums...");
    intent.setType("image/jpeg"); /* This example is sharing jpeg images. */

    ArrayList<Uri> files = new ArrayList<Uri>();
    String path = crtPath +  Name + "/";
    for(int i = 0;i < allsong.size();i++){
        if(allsong.get(i)[0].startsWith(path)){
            File file = new File(allsong.get(i)[0]);
            Uri uri = Uri.fromFile(file);
            files.add(uri);
        }
    }

    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
    Ui.ef.startActivity(intent);
}
 
Example 5
Project: OSS-green-07   File: CardNewsPagerAdapter.java   View Source Code Vote up 6 votes
public Object instantiateItem(ViewGroup container, int position){
    View v = inflater.inflate(R.layout.viewpager_image,null);
    ImageView imgView = (ImageView) v.findViewById(R.id.viewPagerImage);
    //이미지를 가져옴
    Uri uri = Uri.fromFile(new File(cards.get(position)));

    try {
        Bitmap bitmap = MediaStore.Images.Media.getBitmap(inflater.getContext().getContentResolver(),uri);
        int nh = (int) (bitmap.getHeight() * (1024.0 / bitmap.getWidth()));
        Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 1024, nh, true);

        imgView.setImageBitmap(scaled);

    } catch (IOException e) {
        e.printStackTrace();
    }
    container.addView(v);

    return v;
}
 
Example 6
Project: AgentWebX5   File: AgentWebX5Utils.java   View Source Code Vote up 5 votes
static Uri getUriFromFile(Context context, File file) {
        Uri uri = null;

//        LogUtils.i("Info", "::" + context.getApplicationInfo().targetSdkVersion + "   INT:" + Build.VERSION.SDK_INT);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            uri = getUriFromFileForN(context, file);
        } else {
            uri = Uri.fromFile(file);
        }
        return uri;
    }
 
Example 7
Project: EVideoRecorder   File: FileUtils.java   View Source Code Vote up 5 votes
private static Intent getIntentByType(String param, String type) {
    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(param));
    intent.setDataAndType(uri, type);
    return intent;
}
 
Example 8
Project: AndroidHttpUtils   File: FileProviderUtils.java   View Source Code Vote up 5 votes
/**
 * File convert Uri
 *
 * @param context
 * @param file
 * @return
 */
private static Uri getUriForFile(Context context, File file) {
    Uri fileUri = null;
    if (Build.VERSION.SDK_INT >= 24) {
        fileUri = getUriForFile24(context, file);
    } else {
        fileUri = Uri.fromFile(file);
    }
    return fileUri;
}
 
Example 9
Project: DailyStudy   File: PhotoUtils.java   View Source Code Vote up 5 votes
/**
 * 裁剪图片
 * @param uri
 * @param context
 */
public static void startPhotoZoom(Uri uri, Context context, String fileName) {

    File file = new File(context.getExternalCacheDir(), fileName);
    Uri outputUri = Uri.fromFile(new File(file.getPath()));
    String url = FileUtils.getPath(context, uri);

    Intent intent = new Intent("com.android.camera.action.CROP");
    //sdk>=24
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

        Uri imageUri = FileProvider.getUriForFile(context, "com.highway.study.provider", new File(url));//通过FileProvider创建一个content类型的Uri
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra("noFaceDetection", true);//去除默认的人脸识别,否则和剪裁匡重叠
        intent.setDataAndType(imageUri, "image/*");

        //19=<sdk<24
    } else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        intent.setDataAndType(Uri.fromFile(new File(url)), "image/*");

        //sdk<19
    } else {
        intent.setDataAndType(uri, "image/*");
    }
    intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面.
    intent.putExtra("aspectX", 19);// 这两项为裁剪框的比例.
    intent.putExtra("aspectY", 20);// x:y=1:2
    intent.putExtra("outputX", 600);
    intent.putExtra("outputY", 500);
    intent.putExtra("output", outputUri);
    intent.putExtra("outputFormat", "JPEG");// 返回格式
    ((Activity)context).startActivityForResult(intent, CROP_PHOTO);
}
 
Example 10
Project: HeadlineNews   File: IntentUtils.java   View Source Code Vote up 5 votes
/**
 * 获取安装App(支持7.0)的意图
 *
 * @param file      文件
 * @param authority 7.0及以上安装需要传入清单文件中的{@code <provider>}的authorities属性
 *                  <br>参看https://developer.android.com/reference/android/support/v4/content/FileProvider.html
 * @return intent
 */
public static Intent getInstallAppIntent(final File file, final String authority) {
    if (file == null) return null;
    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri data;
    String type = "application/vnd.android.package-archive";
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        data = Uri.fromFile(file);
    } else {
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        data = FileProvider.getUriForFile(Utils.getContext(), authority, file);
    }
    intent.setDataAndType(data, type);
    return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
 
Example 11
Project: VanGogh   File: MainActivity.java   View Source Code Vote up 5 votes
/**
 * 跳转到裁剪页面
 *
 * @param source 需要裁剪的图片
 */
private void startCropActivity(Uri source) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA);
    String imageFileName = "IMG_" + dateFormat.format(new Date());

    Uri uri = Uri.fromFile(new File(getCacheDir(), imageFileName.concat(".jpeg")));
    UCrop.of(source, uri)
            .withAspectRatio(1, 1)
            .withMaxResultSize(1024, 1024)
            .withTargetActivity(VanCropActivity.class)
            .start(this);
}
 
Example 12
Project: what_are_those_app   File: CropScreen.java   View Source Code Vote up 5 votes
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    outputFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myimage.png";
    fileUri = Uri.fromFile(new File(outputFilePath));
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_crop);
    cropped = false;
    captureImage();
}
 
Example 13
Project: amap   File: MIP_OpenFilesUtils.java   View Source Code Vote up 5 votes
public static Intent getChmFileIntent(File file)
{
    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(file);
    intent.setDataAndType(uri, "application/x-chm");
    return intent;
}
 
Example 14
Project: vlc-example-streamplayer   File: AndroidUtil.java   View Source Code Vote up 4 votes
public static Uri FileToUri(File file) {
    return Uri.fromFile(file);
}
 
Example 15
Project: PeSanKita-android   File: PersistentBlobProvider.java   View Source Code Vote up 4 votes
public Uri createForExternal(@NonNull String mimeType) throws IOException {
  return Uri.fromFile(new File(getExternalDir(context),
                      String.valueOf(System.currentTimeMillis()) + "." + getExtensionFromMimeType(mimeType)));
}
 
Example 16
Project: BookyMcBookface   File: TxtBook.java   View Source Code Vote up 4 votes
@Override
protected Uri getUriForSectionID(String id) {
    return Uri.fromFile(getBookFile());
}
 
Example 17
Project: AndroidOCRFforID   File: OcrIdActivity.java   View Source Code Vote up 4 votes
/**
 * Create a file Uri for saving an image
 */
private static Uri getOutputMediaFileUri() {
    return Uri.fromFile(getOutputMediaFile());
}
 
Example 18
Project: binqr-mobile   File: FileOpen.java   View Source Code Vote up 4 votes
public static void openFile(Context context, File file) throws IOException {
    // Create URI
    Uri uri = Uri.fromFile(file);

    Intent intent = new Intent(Intent.ACTION_VIEW);
    // Check what kind of file you are trying to open, by comparing the url with extensions.
    // When the if condition is matched, plugin sets the correct intent (mime) type,
    // so Android knew what application to use to open the file
    if (file.toString().contains(".doc") || file.toString().contains(".docx")) {
        // Word document
        intent.setDataAndType(uri, "application/msword");
    } else if(file.toString().contains(".pdf")) {
        // PDF file
        intent.setDataAndType(uri, "application/pdf");
    } else if(file.toString().contains(".ppt") || file.toString().contains(".pptx")) {
        // Powerpoint file
        intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
    } else if(file.toString().contains(".xls") || file.toString().contains(".xlsx")) {
        // Excel file
        intent.setDataAndType(uri, "application/vnd.ms-excel");
    } else if(file.toString().contains(".zip") || file.toString().contains(".rar")) {
        // WAV audio file
        intent.setDataAndType(uri, "application/x-wav");
    } else if(file.toString().contains(".rtf")) {
        // RTF file
        intent.setDataAndType(uri, "application/rtf");
    } else if(file.toString().contains(".wav") || file.toString().contains(".mp3")) {
        // WAV audio file
        intent.setDataAndType(uri, "audio/x-wav");
    } else if(file.toString().contains(".gif")) {
        // GIF file
        intent.setDataAndType(uri, "image/gif");
    } else if(file.toString().contains(".jpg") || file.toString().contains(".jpeg")
            || file.toString().contains(".png")) {
        // JPG file
        intent.setDataAndType(uri, "image/jpeg");
    } else if(file.toString().contains(".txt")) {
        // Text file
        intent.setDataAndType(uri, "text/plain");
    } else if(file.toString().contains(".3gp") || file.toString().contains(".mpg")
            || file.toString().contains(".mpeg") || file.toString().contains(".mpe")
            || file.toString().contains(".mp4") || file.toString().contains(".avi")) {
        // Video files
        intent.setDataAndType(uri, "video/*");
    } else {
        intent.setDataAndType(uri, "*/*");
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
 
Example 19
Project: aos-FileCoreLibrary   File: ZippedFile.java   View Source Code Vote up 4 votes
@Override
public Uri getUri() {
    // TODO - we may want to use our own zip:// like uri
    // or something like that.
    return Uri.fromFile(mFile);
}
 
Example 20
Project: ultrasonic   File: Util.java   View Source Code Vote up 4 votes
public static void scanMedia(Context context, File file)
{
	Uri uri = Uri.fromFile(file);
	Intent scanFileIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
	context.sendBroadcast(scanFileIntent);
}