So I accidentally deleted the database file in device explorer. I thought a new database would be created, but now I can't view the package in device explorer to check if a new one has been created. Suggestions as to how to fix this?
A simple
Uninstall the app
Reinstall the App.
should fix the issue since the CreateDatbase method wherever you have will be called the moment you add gets installed again.
ALso Database Inspector is not reliable so it takes some time. If you're using SQLLite Database the database won't be visible until you make the db.makeDatabaseReadable() method
Related
I'm having a problem with my users (Android). They delete the app, and their data is gone. They expect it not to be.
Browsing my phone, I see a lot of apps put a folder right off of /internal shared storage. I.E. I click on internal shared storage and there's a bunch of folders for various apps with data in them that doesn't go away if I uninstall the app.
This is what my customers want. This is what will stop them from writing me and accusing me of destroying their data.
How do I get a path to that folder, and what permission do I need to write there?
First off, deleting when the app is gone is how Android works. Anything else is a bug that you should expect to see fixed.
Secondly, you can't put anything right in / anymore. There was a time you could, but that's long since gone.
Third, have you looked into Android Data Backup? https://developer.android.com/guide/topics/data/backup This will work even on a new device, so its a better path forward anyway
I've got an app created with Android Studio.
I'm using an SQLite database which gets downloaded and saved in phone's storage.
The problem is that in certain types of phones (Lenovo / Xiaomi to be exact) the sqlite file gets deleted after some time and the users have to re-download it.
The problem is appearing only on these 2 types of phones and also not all of them.
I can't replicate that on any of the phones I tried nor emulated ones within Android Studio.
There is no code that would delete the SQLite file and also I couldn't find anything in here or google about Lenovo/Xiaomi having similar problems like mine.
Any Ideas, would be appreciated.
I don't know about Lenovo, but Xiaomi phones have a "Clean up" feature that regularly (at least once a week, in my experience) asks the user to, well, let it clean up files. I don't know what it uses to decide if a file is obsolete or not, but it is a very aggressive cleaner (it wants to clean up cache files for apps that have just been used and are in constant use, for example). This is likely what is removing your downloaded files. You can check the location you're downloading them to, and see if changing that helps; or you could see if you can find any documentation on the file cleaner so you can find out how to stop it from flagging your DB as "rubbish".
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
I create an application that is using SQLite in Android. I have no problem when launching it using the Android Virtual Device, everything was fine and all recorded data could be loaded.
Right now, I'm trying to install it on my phone. But, I don't know why, the data can't be loaded. Should I do any configuration on it, or should I put my database file in my project somehow?
In addition, my database name is dbtaxi, and my package name is com.syariati.finalProject.
So im new to working with databases in android, and I cant seem to figure out how to view a created database.
I created the database adapter class and in my main activity class.
I run it in the emulator with no issues, but how do I view the contents?
The book im reading says "examine the file system of the Android device/emulator using DDMS. The database is created under the database folder"
and has an image of the database under a database folder in Eclipse.
I dont know what the first part really means (using DDMS?) and have no idea where the /data/data folder is that people mention.
Even running SQLite3 in CMD and typing ".tables" doesn't yield any database.
In Eclipse Go to Window > Open Persepective > Other > DDMS. Navigate to the DB like the image from the answer below, select the database then click on the floppydisk icon to pull the file from the device on the top right.
In the emulator, the location in DDMS should be /data/data/com.yourNamespace/databases in the File Explorer tab.
This is a pic of the DDMS perspective. In the File Explorer tab on the right, you would drill down to the databases folder. These are virtual folders, so you won't find them on your system. To examine the db, you would select the icon for Pull file from the device (sorry, it got cropped out in this screenshot) and open that file in SQLite.
Retrieve databse from app from cmd
->adb -e shell
--->su root
--->cd data/data/app.name.com/databases
--->cp databasename.db /sdcard/DCIM/
--->exit
--->exit
->adb pull sdcard/DCIM/databasename.db
In android studio run your app in emulator and click on "Device File Explorer"
Explore data/data/{appname}/database. Then right click and save your database file. That's it.
If you did not root your phone, only your app can access your database and it is not possible to view it through DDMS. You will need to implement a function that copies the database to the storage card (make sure you have the external storage permission). From there, you can view your database with an app like aSQLiteManager.
Alternatively, you can just use the Log method along with cursors to print out whatever information you need, but the first method will provide you with a more graphical way of perusing your database.
The database is created on the emulator. Should be in /data/data/[package]/databases/
You can use DDMS to navigate the emulator's filesystem and pull the database file from it to examine locally.
Or you can use sqlite3 on a shell (adb shell) to examine it.