Yêu cầu của tôi là để mở file Asset một ứng dụng từ một ứng dụng khác thông qua nhà cung cấp nội dung. (Tôi phơi bày rằng tập tin với thực hiện ContentProvider)Vấn đề khi mở file tài sản với sự giúp đỡ của nhà cung cấp nội dung
tôi có thể mở vài các tập tin và đọc, nhưng trong khi mở một số tập tin tôi nhận được ngoại lệ. Vui lòng tìm cách triển khai để mở Tệp nội dung.
@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);
}
Một số lần, am.openFd(file_name);
được ném một ngoại lệ nói rằng,
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)
Tuy nhiên, cùng một tập tin tôi có thể mở trong máy tính của tôi hoặc thậm chí trong thiết bị Android dưới hình thức khác.
Bất cứ ai có thể chỉ ra cho tôi, trong trường hợp nào, chúng tôi sẽ nhận ngoại lệ này.
Xin cảm ơn trước.
Nếu chúng tôi thay đổi tiện ích mở rộng như thế này, điều này sẽ không gây ra sự cố khi sử dụng tệp trong ứng dụng nếu ứng dụng mong đợi điều gì đó khác? – clu