My application has android:installLocation="preferExternal" . After the application has been installed and launched , the background services of app gets initiated. When I hard remove the SD card , the application gets crashed giving the "ClassNotFoundException" for the application class (which extend android.app.application) .
Following is the error log:
java.lang.RuntimeException: Unable to instantiate application com.sample.MyApplication: java.lang.ClassNotFoundException: com.sample.MyApplication in loader dalvik.system.PathClassLoader[/mnt/asec/com.com.sample-1/pkg.apk]
How could this be handled in such a way that the crash can be avoided?
I think the app you use that stores the data in the External Storage SD card ,that what the app crash I think.and even the app has been installed in the SD card i think and while to try to retrieve the data your app crashes...
Instead try to move the app from SD card to phone memory by going to setting of the app
If you declare "preferExternal", you request that your application be installed on the external storage, but the system does not guarantee that your application will be installed on the external storage. If the external storage is full, the system will install it on the internal storage. The user can also move your application between the two locations.
If you declare "auto", you indicate that your application may be installed on the external storage, but you don't have a preference of install location. The system will decide where to install your application based on several factors. The user can also move your application between the two locations.
Source
Related
I have an android application coded with Java in Android Studio.
I published my Restful Api to web server.
Whenever i open my android app, the pictures uploaded to the server can not be downloaded to the app via Picasso.
Moreover I can not access these pictures under App_Data folder. Any solutions?
I want to share that answer in case someone needs it.
The accessing problem to my pictures under the App_Data folder was caused by a missing virtual directory matching.
First i created a virtual directory pointing to my pictures folder under App_Data.
Second i tested whether i can access these pictures with chrome browser. if i typed the correct path with the new created virtual directory i can access via web browser.
But the key issue is that i can not access these files again from my app.
I found the reason by deep diving and analyzing.
The actual problem is that:
When i tried to access these files by my android app, Picasso assigns some mapping in its cache. which is under my android app folder.
Because of this cache, no matter i fixed the virtual directory issue Picasso can not access them. Picasso only checks it's cache and if there is a 404 error for that file it doesn't try one more time.
So at the and i completely uninstalled from the device and i installed it again. After that everything is fine!
Edit:clearing picasso cache also works. But it must be used on similar conditions, otherwise clearing picasso cache can affect load times as well as internet usage.
Is it possible to save data to a device upon the installation of my application prior to the opening of the application?
If not, I'm looking for a way I can somehow mark a mobile device as "test device" without my application ever being opened on it (only installed).
If you want to distinguish between the shipped devices and every other device, use the build variants. You can add a variable to the BuildConfig class in gradle and specify a value for this sort of "prerelease" you are making and other for the build you are shipping to the store. Then, in the relevant code, check the value of the variable you created in BuildConfig.
I've got an app that stores few files on sd card. I want my app to remove those files, if user wants to delete the application. How can I do that? Is there a method like onDelete() or something?
I've got an app that stores few files on sd card. I want my app to
remove those files,
Don't store them directly on the sdcard. Use the app's cache space or the directory pointed by getExternalFilesDir. Both are cleaned up by the system when the app is uninstalled
No, there is no way for you app to know when it is being deleted/removed from a device.
Intent.ACTION_PACKAGE_REMOVED
Broadcast Action: An existing application package has been removed from the device.
The data contains the name of the package. The package that is being installed does not receive this Intent.
This comes mostly because if a code would be executed on the app that was about to be removed some might prevent removal etc.
You should provide an option to your users to wipe sdcard data, or use another storage option (that is linked to your app), but I guess you're using the sdcard on purpose.
HTML5 app (Cordova Supported)
is running on Google Play and i do hold lot of local storage items of user . Now i am going to release Android pure native app so i don't want user to register again for my app instead i want to use earlier local storage items from app which is running.
Using those earlier user preferences stored in local storage , i would rather not to run new registration and run on old user registration Preferences .
Is their any way that i can do it ??
Following steps can answer it precisely :
Keep Cordova in your android native build .
Keep index.html in Assest folder .
Run Webview(index.html) using cordova
Fetch local storage variables using window.location .
Run Only first time with splash screen and as soon as you get the all the existing app storage variables and later on never start run the app with webview only native view completely.
Store all variables in SharedPreferences.
I am working on a rooted device.
I have connected with the adb shell from my pc and I can verify that the other database exists and I can query its tables.
However in the my java code when I try to open the database I get error
android.database.sqlite.SQLiteException: unable to open database file
I am trying to open the database like this:
SQLiteDatabase.openDatabase(PATH, null, SQLiteDatabase.OPEN_READONLY);
The path is something like /data/data/com.xxx.xxx/databases/xx.db
Am I supposed to read the databases of other applications like this or there is another way?
UPDATE:
I also tried making the system app as adviced in this thread Push my apk to /system/app
I think it works because the app cannot be uninstalled after that from the applications manager like the ordinary apps so I think it is a system app. But still I cannot access the database though I am sure the paths and permissions are ok.
Android OS by default does not allow applications to access each others private folders. To be able to read files that are in another applications folder either:
1) you need to have both applications installed using same user id. Add this to both manifests:
android:sharedUserId="com.xx.xx"
2) If other app is a 3rd party app then your only choice is to install your app as system application. To do that you need a rooted phone and you need to mount the system folder. And then you need to put your application into /system/app/ folder and reboot the phone. It should be installed automatically during the boot.
I would assume that the permissions on the database files are set such that your application has no acess. Even if your device is rooted it doesn't mean that your application is running as root.
This is because the app needs root, and needs to change the permissions of the database you are trying to access so that you can actually access it. What you will need to do is, as root, change the permissions of the database so that everyone can access it, do what you would like on the database, close the database and change the permissions back.
This does circumvent security of android, so proceed at your own risk. You can find a code sample at:
http://rratmansky.wordpress.com/?p=259&preview=true