How to use support FileProvider for sharing content to other apps?

前端 未结 9 2212
野的像风
野的像风 2020-11-22 14:01

I\'m looking for a way to correctly share (not OPEN) an internal file with external application using Android Support library\'s FileProvider.

Following the example

9条回答
  •  没有蜡笔的小新
    2020-11-22 14:47

    If you get an image from camera none of these solutions work for Android 4.4. In this case it's better to check versions.

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (intent.resolveActivity(getContext().getPackageManager()) != null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            uri = Uri.fromFile(file);
        } else {
            uri = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", file);
        }
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        startActivityForResult(intent, CAMERA_REQUEST);
    }
    

提交回复
热议问题