I followed this guide for download expansion files. When I checked it, the download worked fine, but when I wanted to uninstall the application from the phone the files stayed there.
How can I cause the files to be deleted with the app?
Downloaded expansion file(s) will be stored in your shared-storage folder (usually this is your sd-card). There is no code that can be triggered when uninstalling your application. This unfortunately means that you cannot remove expansion files from code when uninstalling the application.
However I did find out that on my Nexus 4 but also on a Samsung Galaxy S the expansion file is automatically deleted from the shared-storage folder when uninstalling the application. I tested this using an application that is in the play store.
When the expansion file is not deleted automatically then the only way to get rid of your expansion files after an uninstall would be to manually delete the file(s) from your shared-storage folder. An end-user can be instructed to remove the expansion file manually by letting him/her attach the device to the computer and navigate to:
<shared-storage>/Android/obb
In this folder you should see one or more folders with package names. Pick the folder that will contain your expansion file and delete the package folder or the expansion file depending on what you wish to be deleted. Be aware that deleting the wrong package can affect different apps. So use manual deletion with caution!
Some reasons why an expansion can't be deleted by end-user:
End-user doesn't have drivers for the device so it can't see what's on the shared-storage
End-user uninstalled the application and the expansion file is already gone
Store your app files in the Applications private directory.
This can be obtained with getFilesDir()
When your application is uninstalled, all files in this directory get deleted.
Related
I have an obb file which is a zip file, which I unpack after downloading it in the obb folder. Then I copy the unpacked obb files to Internal Storage.
I just released an app to Internal testing. I installed the app, but I was hoping that the obb files would be automatically deleted, but it seems they are still hanging in there, and when I check the Storage size in Settings, the size of the apk file includes the data in the obb folder. I don't want this, because my app is taking less storage then it's actually showing in Settings / Storage.
Is there an Android process that automatic removes the obb files later on, or do I need to delete them myself when I don't need them anymore, right after copying them to internal storage?
The answer is no. The only time the OBB file gets deleted is when the user uninstalls the app. Or when the app deletes the file itself.
On a side note, which I happened to find out only later, if you delete or rename your OBB file, it gets re-downloaded every time you release an app update. So you are better off using the OBB file as is and leave it there as originally installed, and using a second OBB file for updates (your listed app size will include the OBB file though), or another option is using a file hosting service such as Dropbox if you don't want the OBB file just sitting there.
I'm trying to find a way to create an apk file to extract files to certain path while installing to use these files in my main app.
In other words I need to add expansion files to my main app by installing another apk that won't be displayed in the launcher.
And play store expansion files is not an option.
What you need is an Expansion file configured as a patch.
This question has some info about it, but you should go to the official documentation about how to download an expansion file after installing your main application.
I am trying to modify an APK which came with my official firmware.
Actually only some resources should be modified (sounds should be replaced with silent files).
I moved APK and ODEX to backup folder, unzipped APK on a PC, modified files, zipped APK with 7Zip again and placed it into /system/app folder with corresponding permissions. After a reboot Camera application disappeared from everywhere.
Ok, I copied ODEX file back to /system/app, rebooted, and application appeared, but trying to run it makes it crash.
APK file has no DEX inside.
I thought that ODEX file contains code only and shouldn't be re-created.
What I was doing wrong and how to do it right?
You can't modify apk's without signing them again. The Android system will notice that the apk has been tampered with and refuse to load it. You could sign it with your own key, but then your signature wont match the official signature for that package name and that will prevent you from getting any updates for that application as long as your modified apk is installed. Also if that application is relying on being signed with the same certificates as other applications from the same manufacturer it wont work correctly.
You can read about signing android applications in the official documentation
Why do you want to do this?
This is a very interesting thing. I have an APK file, com.company.app.apk. When installed to an emulator by using Eclipse, by using the following code to get the apk's file name:
String fileName = activity.getPackageManager().getApplicationInfo(
activity.getPackageName(), PackageManager.GET_META_DATA).publicSourceDir;
I get a pathname like this com.company.app-1.apk. The file size is the same as the apk file I built.
Now when I publish this app to Market, and install it to a real device (Android 2.3), the same code returned a pathname like this: com.company.app-2.zip. Note that the file extension has changed to .zip and, most importantly, the file size is significantly smaller than the original size.
Now if I transfer these two files to my PC and use WinZip to open them, I found one really interesting thing:
The one installed on emulator by Eclipse has exactly the same stuff as I expected. Namely: the code ('com' folder), the resource ('res' folder), the signature ('META-INF' folder), the assets ('assets' folder), and the manifest file (AndroidManifest.xml). However, the one installed on a real device by Market has only two parts: the resource, and the manifest file.
Question: I think when installed from Market, the .apk file is split into two (or more) files. One file is pointed to by ApplicationInfo.publicSourceDir, which contains only the resource. How can I get the pathname to the other file(s)?
ADDED: I have two versions of the same app, one is paid using Google's Vendor Licensing Service, the other is free. The above mentioned phenomenon happens only to the paid version. Why?
Correction: When I said the 'com' folder exists in the installed apk file in the first case, I should be more clear. The code per se, the *.java files, are not in the 'com' folder. As a matter of fact, the 'com' folder contains only a few garbage files that were inadvertently left there during the build process. If not for those garbage files, I don't think the 'com' folder would be there in the first place.
I think you are not right. The market works in the following way: you choose an application and push a button to install it. After that market sends the intent to gtalk service to install the application. This service downloads apk file that you've uploaded to the market and when finishes it installs this apk. Just during the installation can some changes happen. It seems to me that from the application during the installation classes.dex file is extracted and from this file optimized dex (.odex) is produced and put in the separate directory. That's why you see the difference in the files.
Ok, here is what I've found out, in case this helps someone out there:
When Market installs the free version of my app, the apk file is installed to /data/app/com.company.app.apk, the file content is exactly the same as I built it, same file size, same everything.
For the paid version that uses Market Vendor Licensing, the apk file itself is installed to /data/app-private/com.company.app.apk. This is the same file as I released. However, the resources are extracted and installed to another file /data/app/com.company.app.zip, note the file extension. This zip file contains only resources, so it's significantly smaller. But the .apk file in /data/app-private has everything, so the file size is the same as I built it.
ApplicationInfo.publicSourceDir always points to the file in /data/app, so it's /data/app/com.company.app.zip in the paid version's case, and /data/app/com.company.app.apk for the free version. For the paid version, I obtained the pathname from publicSourceDir, then replace.app with app-private, and replace .zip with .apk to get the original file.
If I install the apk directly to an emulator, then there is only one file and is always installed under /data/app.
Is there a way in Eclipse ADT to ignore a certain set of files under the Package Explorer when exporting an APK package?
I have a PhoneGap application that reuses a whole bunch of js/css/images with another application, but currently the APK export is including everything under my "assets" directory, inflating the APK size as a result. Ideally, I only want certain js/css/image files under my "assets" directory to be included in the package instead of everything.
I don't think that there is any support in the SDK/API to achieve this directly but you put your shared resources into a directory on to the memory card and refer to them there from your app? Though your next question is how would you 'install' the shared images etc without including them in the .apk file.. which I'm not sure of the answer.