Patching an Android app - android

I have an Android app with an expansion file already attached. This is all working fine.
The file is: main.2.com.mydomain.myapp.obb
I want to update some assets in my app so I planned on adding a patch expansion file. Going by the next version iteration this file was: patch.10.com.mydomain.myapp.obb
I've uploaded an alpha build and I can see the files are downloading successfully. The assets in question are videos so I have the following code to access them:
ZipResourceFile expansionFile= null;
AssetFileDescriptor fd= null;
try {
expansionFile = APKExpansionSupport.getAPKExpansionZipFile(getApplicationContext(),2,10);
fd = expansionFile.getAssetFileDescriptor("myvideo.mp4");
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
My understanding is that the getAPKExpansionZipFile call will merge the two expansion files but my questions are:
If my patch file contains a file of the same name as the original main expansion, will the patch file version take precedent or should I have new filenames in my patch file (e.g. patch_myvideo.mp4)
How do I know the video will be correctly loaded from the patch file? I tried checking the AssetFileDescriptor offsets (start, length etc..) but it was the same with and without the patch file call.
Would love to know if I'm on the right track here!
Thanks for any help.

Related

How to cache audio for offline use in Android Studio

I am developing an Android application in which I need to get the specified audio file from my website when the user plays it, but I don't want to stream it or download it every time, just the first time. So I was thinking of caching it and play offline whenever the user is in need. So please suggest any method to do so. Or if exists any other method rather than caching like downloading the actual file to file storage and play whenever needed.
If you need to cache files, you should use createTempFile(). For example, the following method extracts the file name from a URL and creates a file with that name in your app's internal cache directory:
private File getTempFile(Context context, String url) {
File file;
try {
String fileName = Uri.parse(url).getLastPathSegment();
file = File.createTempFile(fileName, null,
context.getCacheDir());
} catch (IOException e) {
// Error while creating file
}
return file;
}
You can also see here for more about caching files.
https://developer.android.com/training/data-storage/files.html#WriteCacheFileInternal
Hope this will help.

Android - How can i create a "black list" for the files of my application

In my app i have many files (images and audio files). There is a way i can "mark" this files so that they cannot be read from other app like music player for the audio and gallery for the images? My question is: i can create a sort of "black list" that prevents to other app to see my files?
EDIT
As was recommended to me, i try making a ".nomedia" file into the folder that contains my files in this way:
File no_media_file = new File (my_path, "/.nomedia");
try {
no_media_file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
the file ".nomedia" is created correctly (i verified using "ES File Explorer") but if i open "play music" app i can still play my audio file... Where am i doing wrong?
I solved my problem by inserting my files in a folder named like this: ".my_folder" and it's worked!

Class Recognition; R.drawable.balloons

Okay, I seem to be having a small issue with R.drawable.balloons. I'm trying to use a template for building a private external storage file that I found on Android Developer, but balloons keeps giving an error (cannot be resolved or is not a field). I was wondering if I could get some help fixing it.
Here's the code section it sits in:
void createExternalStoragePrivateFile() {
// Create a path where we will place our private file on external
// storage.
File file = new File(getExternalFilesDir(null), "DemoFile.jpg");
try {
/*
Very simple code to copy a picture from the application's
resource into the external file. Note that this code does
no error checking, and assumes the picture is small (does not
try to copy it in chunks). Note that if external storage is
not currently mounted this will silently fail.
*/
// Creates file to stream picture
OutputStream os = new FileOutputStream(file);
// Allows app to accept the picture
InputStream is = getResources().openRawResource(R.drawable.balloons);
byte[] data = new byte[is.available()];
is.read(data);
os.write(data);
is.close();
os.close();
} catch (IOException e) {
// Unable to create file, likely because external storage is
// not currently mounted.
Log.w("ExternalStorage", "Error writing " + file, e);
}
}
A heads up, in case I get called out for being a copy/paster, this is only supposed to be a template, but I would like to test that it works before I make changes. Sorry.
You need an image named balloons in the res\drawable folder of your project (or any of its variants, such as drawable-hdpi, &c). The R class is autogenerated.
See How do I add R drawable android?

File folder on Eclipse Android

I would like to make a xml file that will be modified during the execution of the application and i want to keep it after i close it for the next time i open it.
The first problem is that i don't know where do i have to put the file in the package explorer on Eclipse.
If i put the file on res/raw/ folder i could just read the file, but i can't modify.
I'm working with Jdom2.
The file is a score table for a game that will be modified every time the player finish a game.
That's the code i actually have to read the xml file stored on res/raw
try
{
puntf = getResources().openRawResource(R.raw.punt);
} catch (Exception ex)
{
Log.e("Ficheros", "Error");
}
And that's the code i actually have to modify the xml file(with Jdom2). But of course, that is wrong.
public void escritura()
{
try
{
xmlOutput.output(puntu, new FileOutputStream("punt.xml"));
}
catch (Exception e) {
e.printStackTrace();
}
}
Thanks a lot for your answers.
If you want to save a file and modify it programmatically I would suggest you to store it in this path:
/data/data/com.yourpackage.app/punt.xml
I have never worked with Jdom2, but you can have access to it by adding these lines of code:
File puntFile= new File("data/data/com.yourpackage.app/punt.xml");
FileOutputStream fos = new FileOutputStream(puntFile);
xmlOutput.output(puntu, fos);
You can also see the file in DDMS in file explorer. Just follow that path.
I can't understand if you want to save and edit the file during the process of your application or just save it somewhere before the app starts and edit it afterwords. If so, please give more details about that.
Hope I helped...
You should read uo on storage options on Andriod: THere's an article on this.... Use the resulting input and output streams for JDOM.

How to play video from apk expansion files?

I create developing app in android which have about 500 mb video i use for uploading apk expansion files method i upload expansion and download it but now i cant play videos from it http://blogmobile.itude.com/2012/11/22/expanding-your-horizons-using-expansion-files-for-android/ i follow this example for playing video but it's not working with me http://ktakeda47.blogspot.com/2012/04/apk-expansion-files.html i followed this link for expansion file downloading .Now plz help me how to play videos from expansion file Dir="/sdcard/Android/obb" ?
I'm using the following code to play mp4 from obb APKexpansion file using APKExpansionSupport lib:
ZipResourceFile expansionFile = null;
AssetFileDescriptor mAFD= null;
try {
expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this, 1, 0);
mAFD = expansionFile.getAssetFileDescriptor(strVideoFile);
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
if (expansionFile==null || mAFD == null){
Toast.makeText(this, "obb is not here or doesn't contain file: "+strVideoFile, Toast.LENGTH_LONG).show();
return false;
}
mMediaPlayer.setDataSource(mAFD.getFileDescriptor(), mAFD.getStartOffset(), mAFD.getLength());
Remember - you have to pack obb zip archive without any compression level. This is very important. It must be a zip archive with no compression (level=0).
However there is a URI mentioned in APKES docs (speaking of VideoView) but I cant get a glue how to get the URI from APKES. Finally I found how to do it here
So to use URI you has to extend com.android.vending.expansion.zipfile.APEZProvider like in his example and make changes to Manifest and it should work.

Categories

Resources