Commit 420aedc7 authored by jehan's avatar jehan
Browse files

add java method to android’s helper to copy assets instead of resource

parent d865f171
......@@ -180,6 +180,11 @@ public class AndroidPlatformHelper {
}
private void copyAssetsFromPackage() throws IOException {
Log.i("Starting copy from assets to application files directory");
copyAssetsFromPackage(mContext, "org.linphone.core",".");
Log.i("Copy from assets done");
Log.i("Starting copy from legacy resources to application files directory");
/*legacy code for 3.X*/
copyEvenIfExists(getResourceIdentifierFromName("cpim_grammar"), mGrammarCpimFile);
copyEvenIfExists(getResourceIdentifierFromName("vcard_grammar"), mGrammarVcardFile);
copyEvenIfExists(getResourceIdentifierFromName("rootca"), mLinphoneRootCaFile);
......@@ -187,6 +192,7 @@ public class AndroidPlatformHelper {
copyEvenIfExists(getResourceIdentifierFromName("ringback"), mRingbackSoundFile);
copyEvenIfExists(getResourceIdentifierFromName("hold"), mPauseSoundFile);
copyEvenIfExists(getResourceIdentifierFromName("incoming_chat"), mErrorToneFile);
Log.i("Copy from legacy resources done");
}
public void copyEvenIfExists(int ressourceId, String target) throws IOException {
......@@ -220,6 +226,34 @@ public class AndroidPlatformHelper {
lOutputStream.close();
lInputStream.close();
}
public static void copyAssetsFromPackage(Context ctx,String fromPath, String toPath) throws IOException {
new File(ctx.getFilesDir().getPath()+"/"+toPath).mkdir();
for (String f :ctx.getAssets().list(fromPath)) {
String current_name = fromPath+"/"+f;
String current_dest = toPath+"/"+f;
InputStream lInputStream;
try {
lInputStream = ctx.getAssets().open(current_name);
} catch (IOException e) {
//probably a dir
copyAssetsFromPackage(ctx,current_name,current_dest);
continue;
}
FileOutputStream lOutputStream = new FileOutputStream(new File(ctx.getFilesDir().getPath()+"/"+current_dest));//ctx.openFileOutput (fromPath+"/"+f, 0);
int readByte;
byte[] buff = new byte[8048];
while (( readByte = lInputStream.read(buff)) != -1) {
lOutputStream.write(buff,0, readByte);
}
lOutputStream.flush();
lOutputStream.close();
lInputStream.close();
}
}
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment