在我的應用程序中,用戶可以選擇文件並在適當的應用程序中打開它們(使用ACTION_VIEW意圖)。 我需要在將數據提供給其他應用程序之前對數據進行一些處理。所以我正在使用一個流解決方案:我實現了一個ContentProvider,它實現了openTypedAssetFile
和writeDataToPipe
(此方法填充由openPipeHelper
創建的輸出ParcelFileDescriptor)。Android Gallery不支持流式文件
這個作品:我可以打開.pdf文件,.txt文件等流媒體似乎是正確的。 我可以使用3方應用程序打開圖像。 然而,當我打開使用Gallery
的圖像,這是行不通的(圖庫顯示黑屏),我也得到了以下異常:
fail to open myfile.jpg
UriImage(21890): java.io.FileNotFoundException: Not a whole file
我看看畫廊源(here)和我能看到異常拋出這裏:
try {
if (MIME_TYPE_JPEG.equalsIgnoreCase(mContentType)) {
InputStream is = mApplication.getContentResolver()
.openInputStream(mUri);
mRotation = Exif.getOrientation(is);
Utils.closeSilently(is);
}
**mFileDescriptor = mApplication.getContentResolver()
.openFileDescriptor(mUri, "r");**
if (jc.isCancelled()) return STATE_INIT;
return STATE_DOWNLOADED;
} catch (FileNotFoundException e) {
Log.w(TAG, "fail to open: " + mUri, e);
return STATE_ERROR;
}
然而,在Gallery應用程序一次,如果我選擇「設置爲牆紙」,然後我可以看到我的形象,它是那麼好流。所以當圖庫打開時出現問題。
經過深入瞭解(在ContentResolver代碼等),我不明白爲什麼它的行爲如此。看起來Gallery
不支持流文件。是對的嗎 ? 你有什麼想法嗎?
非常感謝。
創建您自己的畫廊然後訪問選擇的圖像,HTTPS:/ /github.com/luminousman/MultipleImagePick – Rohit