2010-07-05 5 views
7

내 요구 사항은 콘텐츠 공급자를 통해 다른 응용 프로그램에서 하나의 응용 프로그램의 자산 파일을 열 수 있습니다. 나는 몇 가지를 열 수 있어요문제 동안

(I는 컨텐트 프로 바이더의 구현이 파일을 노출하고있다) 파일 및 읽기,하지만 일부 파일을 여는 동안 나는 예외가 발생했습니다. 자산 파일을 여는 구현을 찾으십시오.

@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) 

하지만, 내 PC에 또는 다른 방식으로 안드로이드 장치에서 열 수있는 동일한 파일

.

누구나 나를 가리킬 수 있습니까, 어떤 시나리오에서 우리는이 예외를 얻을 것입니다.

미리 감사드립니다.

답변

12

안드로이드는 * .mp3 파일처럼 유용하지 않다면 모든 애셋을 압축하려고 시도합니다. 압축되지 않은 파일 유형의 전체 목록이 있는지 모르겠지만 파일의 이름을 .mp3 (압축 여부는 확장자 만 기반으로 결정)의 이름을 변경하는 경우 괜찮습니다.

약간의 구글 검색이 밝혀 : 당신이 빌드 프로세스에 충분한 제어가있는 경우

http://osdir.com/ml/android-ndk/2010-04/msg00086.html

, 당신은 자산을 추가 zip 또는 aapt에 함께 "-0"플래그를 사용할 수 있습니다. 위 링크를 인용에서

-0 specifies an additional extension for which such files will not 
    be stored compressed in the .apk. An empty string means to not 
    compress any files at all. 

aapt에 안드로이드 버전의 \ 도구

디렉토리

은 당신의

안드로이드 SDK의 \ 플랫폼에 \ 위치 :

static const char* kNoCompressExt[] = { 
".jpg", ".jpeg", ".png", ".gif", 
".wav", ".mp2", ".mp3", ".ogg", ".aac", 
".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet", 
".rtttl", ".imy", ".xmf", ".mp4", ".m4a", 
".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2", 
".amr", ".awb", ".wma", ".wmv" 
}; 
+0

확장 프로그램을 이와 같이 변경하면 다른 파일을 기대하는 경우 앱에서 파일을 사용할 때 문제가 발생하지 않습니까? – clu