7
我的要求是,從通過內容提供商另一個應用中打開一個應用程序的資源文件。(我揭露與ContentProvider的實現,文件)問題,同時打開資產文件與內容提供商的幫助下
我能開幾文件和閱讀,但同時打開一些文件,我收到異常。請找到打開資產文件的實施。
@Override
public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
AssetManager am = getContext().getAssets();
String file_name = uri.getLastPathSegment();
if(file_name == null)
throw new FileNotFoundException();
AssetFileDescriptor afd = null;
try {
afd = am.openFd(file_name);
} catch (IOException e) {
e.printStackTrace();
}
return afd;//super.openAssetFile(uri, mode);
}
有些時候,am.openFd(file_name);
拋出一個異常說,
java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
at android.content.res.AssetManager.openAssetFd(Native Method)
at android.content.res.AssetManager.openFd(AssetManager.java:329)
at com.pineone.swfinstaller.SwfProvider.openAssetFile(SwfProvider.java:25)
at android.content.ContentProvider$Transport.openAssetFile(ContentProvider.java:218)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:234)
at android.os.Binder.execTransact(Binder.java:288)
at dalvik.system.NativeStart.run(Native Method)
但是,相同的文件,我可以在我的電腦,甚至在一些其他的方式Android設備打開。
任何人都可以指出,在什麼情況下,我們會得到這個例外。
在此先感謝。
如果我們像這樣更改擴展名,那麼在應用程序中使用該文件時,如果期待其他內容,這不會引起問題嗎? – clu 2015-11-11 04:24:03