현재 앱이 50MB가 넘어 apk extension으로 이미지 파일을 밖으로 빼서 등록을 하려고 하는데요.
http://developer.android.com/google/play/expansion-files.html#Overview
위 주소를 참고하여 진행하였고 테스트 진행했을 때 extension file 다운로드까지는 잘 되는 상태입니다.
문제는 extension file에서 이미지를 불러오는 방법을 못찾고 있는 건데요.
현재 위 매뉴얼의 코드는 다 입력했고 구글링으로 아래와 같이 이미지를 불러오려고 하는데 어디가 틀린건지,
어떻게 수정해야되는지 고수님들 확인 좀 부탁드릴게요!ㅠ 이거 안되서 지금 며칠째 고민하다 글 올려요ㅠ
// main 페이지 내의 소스들
//이미지 불러오기
public AssetFileDescriptor getAssetFileDescriptor(String filePath) {
PackageManager manager = this.getPackageManager();
PackageInfo info;
try {
info = manager.getPackageInfo(this.getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return null;
}
String thePackageName = this.getPackageName();
int thePackageVer = info.versionCode;
String zipFilePath = Environment.getExternalStorageDirectory() + "/Android/obb/" + thePackageName + "/main."
+ thePackageVer + "." + thePackageName + ".obb";
ZipResourceFile expansionFile = null;
AssetFileDescriptor afd = null;
try {
expansionFile = new ZipResourceFile(zipFilePath);
afd = expansionFile.getAssetFileDescriptor(filePath);
} catch (IOException e) {
e.printStackTrace();
}
return afd;
}
oncreate 내의 이미지를 불러오는 코드
//아래 코드로 이미지를 불러오는데 앱은 정상적으로 작동됩니다. 그러나 getAssetFileDescriptor에서 이미지를 불러와 보여줘야 하는데 이를 며칠째 보고만 있습니다. 고수님들 확인 좀 부탁드려요 ! ㅠ
//이미지 불러오기
AssetFileDescriptor readFile = getAssetFileDescriptor("bmp/alton_mtb_2015_alton_1_8_g_l_s_t_image1.bmp");
Bitmap image = null;
if( readFile != null ) {
try {
Log.d("test1", "test");
Drawable d = Drawable.createFromStream(readFile.createInputStream(), null);
image = ((BitmapDrawable)d).getBitmap();
} catch (IOException e) {
Log.d("test2", "test");
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//이미지뷰에 image 값 받아오는지 여부 테스트 진행
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(image);
또 링크 매뉴얼에 아래와 같은 코드가 있는데 위에 코드와 중복되는 것인지, 아니면 따로 필요한 것인지도 확인 부탁드려요!
// The shared path to all app expansion files
private final static String EXP_PATH = "/Android/obb/";
static String[] getAPKExpansionFiles(Context ctx, int mainVersion,
int patchVersion) {
String packageName = ctx.getPackageName();
Vector<String> ret = new Vector<String>();
if (Environment.getExternalStorageState()
.equals(Environment.MEDIA_MOUNTED)) {
// Build the full path to the app's expansion files
File root = Environment.getExternalStorageDirectory();
File expPath = new File(root.toString() + EXP_PATH + packageName);
// Check that expansion file path exists
if (expPath.exists()) {
if ( mainVersion > 0 ) {
String strMainPath = expPath + File.separator + "main." +
mainVersion + "." + packageName + ".obb";
File main = new File(strMainPath);
if ( main.isFile() ) {
ret.add(strMainPath);
}
}
if ( patchVersion > 0 ) {
String strPatchPath = expPath + File.separator + "patch." +
mainVersion + "." + packageName + ".obb";
File main = new File(strPatchPath);
if ( main.isFile() ) {
ret.add(strPatchPath);
}
}
}
}
String[] retArray = new String[ret.size()];
ret.toArray(retArray);
return retArray;
}
그럼 미리 감사합니다. !