0
我正在開發一個應用程序,允許用戶拍照,在他們身上繪製,然後將其上傳到我們的社交媒體應用程序中。我想爲繪圖使用第三方應用程序來減輕我們的工作負擔。我在這裏找到了很多關於如何這樣做的答案,下面的代碼大部分來自這些答案。當我嘗試不同的答案組合時,我總是在意圖上得到Toast錯誤。我得到的兩個錯誤是「文件無法打開」和「圖像無法編輯」。前者聽起來像文件權限問題,我認爲應該從grantUriPermissions下面的解決方法中解決。另一個我不知道的錯誤。Android ACTION_EDIT意圖編輯圖像
// Code taken from answer on http://stackoverflow.com/questions/15699299/android-edit-image-intent
final Uri uri = Uri.parse(this.photoPath);
int flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION;
Intent editIntent = new Intent(Intent.ACTION_EDIT);
editIntent.setDataAndType(uri, "image/*");
editIntent.addFlags(flags);
editIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
// This work-around allows the intent to access our private FileProvider storage.
// Code taken from http://stackoverflow.com/questions/24835364/android-open-private-file-with-third-party-app
List<ResolveInfo> resInfoList = this.getPackageManager().queryIntentActivities(editIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
this.grantUriPermission(packageName, uri, flags);
}
startActivityForResult(Intent.createChooser(editIntent, null), EDIT_INTENT);
有人看過這些Toast消息並能解決它們嗎?
'photoPath'指向哪裏?還要注意那些'Intent'標誌和那個'grantUriPermission()'循環對於文件是沒有用的;那些用於'ContentProvider'的'Uri'值,比如'FileProvider'。另外,'putExtra()'調用是無用的,因爲EXTRA_OUTPUT用於ACTION_IMAGE_CAPTURE和ACTION_VIDEO_CAPTURE,而不是ACTION_EDIT Intent.html#ACTION_EDIT)。 – CommonsWare
photoPath是在前面創建的文件上調用.getAbsolutePath()的結果。該文件正由應用程序中的FileProvider管理,爲什麼我覺得我需要該循環。我可能會誤解這一點;我不知道Android文件權限的所有細節。 – BowlingHawk95