ファイルを内部のストレージにインポートできるアプリを作成しました。 外部のアプリケーション(PFビューアやPhotosなど)でファイルを開くために、私はこれらのガイドに従ってみました:、topic1、topic2、topic3およびtopic4しかし成功しません。ここでFileProviderを使用する理由私は内部アプリケーションから外部アプリケーションでファイルを開くことができませんか?
は私のコードです:
私のマニフェスト
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.myapp.chatcher"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
私のパッケージの値に:package="com.myapp.catcher"
私file_paths.xml
<paths
xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="projection" path="." />
</paths>
私のコード
例えばPRIVATE -> shelf1 -> my files
-> shelf2 -> my files
-> shelfN -> my files
:私はこのような階層を作成
String fileName = path.substring(path.lastIndexOf("/") + 1);
String shelf = path.substring(path.lastIndexOf("PRIVATE") + 8, path.lastIndexOf("/"));
File filePath = new File(mContext.getFilesDir(), "PRIVATE".concat("/").concat(shelf).concat("/"));
File newFile = new File(filePath, fileName);
Uri contentUri = FileProvider.getUriForFile(mContext, "com.myapp.chatcher", newFile);
Intent myIntent = new Intent();
myIntent.setAction(Intent.ACTION_VIEW);
myIntent.setData(contentUri);
myIntent.setType(mimeType);
myIntent.setFlags(FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_WRITE_URI_PERMISSION);
mContext.startActivity(myIntent);
data/user/0/com.myapp.chatcher/files/PRIVATE/testshelf/Screenshot_2017-01-04-09-45-13.png
newFile.getAbsolutePathを(印刷結果)
/data/user/0/com.myapp.chatcher/files/PRIVATE/bogl/imagetest.jpg
でこのコードは、でセレクタを開き「写真」をクリックして「imagetest.jpg」を表示せずに、「写真アプリ」を開きますが、すべての写真があるフォルダを開きます。 私はpdfファイルを試してもpdfを開かず、 "no media"というメッセージが表示されます。
私のコードで何が問題になっていますか?
コメントが拡張議論のためではありません。この会話は[チャットに移動]されています(http://chat.stackoverflow.com/rooms/133634/discussion-on-question-by-machoprogrammer-why-using-a-fileprovider-i-cant-open)。 –