다음 설정이 있지만 타사 앱에서 파일을 열 때 파일을 찾을 수 없습니다.Android Java : 다른 앱에서 FileProvider를 사용하여 다운로드 한 파일을 여는 방법
파일을 다운로드 한 후 (바이트 단위로) 저장합니다.
public File storeFile(byte[] b, String ref) throws IOException {
String path = String.valueOf(ref).replaceAll("/+", "_");
final File f = new File(A.getDir(path, Context.MODE_PRIVATE), "downloads");
FileOutputStream out = new FileOutputStream(f);
out.write(b);
out.flush();
out.close();
return f;
}
는 다음을 읽고 그것을 열어보십시오.
try {
Uri uri = Uri.fromFile(storeFile(bytes, ref));
MimeTypeMap mime = MimeTypeMap.getSingleton();
Intent i = new Intent(Intent.ACTION_VIEW);
String type = mime.getMimeTypeFromExtension(ext);
File imagePath = new File(getFilesDir(), "downloads");
File file = new File(imagePath, uri.getPath());
Uri newUri = FileProvider.getUriForFile(context, "com.do.app.fileprovider", file);
i.setDataAndType(uriContent, type);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
A.startActivity(i);
} catch (IOException e) {
e.printStackTrace();
}
그리고
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.do.app.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
매니페스트에서 경로
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path name="cloud_files" path="downloads"/>
</paths>
내가 누락 찾을 수없는 것. 그냥 imagePath.getAbsolutePath()
및 f.getAbsolutePath()
비교
File f = new File(A.getDir(path, Context.MODE_PRIVATE), "downloads");
에서 사용되는 완전히 다른 디렉토리입니다
'FileProvider.getUriForFile()' 괜찮습니까? uri.toString()의 값을 말해주세요. – greenapps