私はFileProviderクラスを使用して終了し、以下のコードでサポートされているドキュメントを歩きました。 ( - ファイルを編集/保存されます - ユーザーがボタンを押すと、ユーザーがアプリに戻る)私はもともと行う上で意図されたが、概念的には、結果は同じではありませんかなり何:
(AndroidManifest.xmlに>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="my.package.name.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
でおよび解像度/ XML/file_paths.xml中:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="notes" path="notes/"/>
</paths>
と(ユーザが表示/自分のノートを編集することが期待される)ボタンリスナーで:
private class AddNoteListener implements View.OnClickListener {
@Override
public void onClick(View v) {
File notesPath = new File(context.getFilesDir(), "notes");
if (notesPath.exists() == false) {
notesPath.mkdir();
}
File newFile = new File(notesPath, "my_note.txt");
try {
if (newFile.exists() == false) {
newFile.createNewFile();
}
Uri contentUri = FileProvider.getUriForFile(context, "my.package.name.fileprovider", newFile);
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setDataAndType(contentUri, "text/plain");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
context.startActivity(Intent.createChooser(intent,"Title"));
} catch (IOException ioe) {
e.printStackTrace();
}
}
}
参考文献:
Granting permissions
Proper mime type
FileProvider