Android App with a database crashes - android

I've built an android application with a database (sqlite 3) targeted for Android 2.2 with API level 8. It works by copying the database from the assets directory to the /data/data/com.myapp.db/databases folder. It works just fine on the emulator. However, when I try to install the application on HTC mobile device with version 2.2 and 2.1-update1, it crashes. The error says "Failed to Copy the Database". Could this be as a result of the database path that I used on the emulator and the actual device mismatching? I'm eagerly looking for your answers.
Thanks

I think it's a matter of permissions. The application has limited access to the system folder, unless you have your device rooted. The database you create from your application is saved under application directory. Maybe i didn't properly understand your issue, but... you are not creating a new database, but just moving a database you have in your assets to a final directory?. Where does this database in assets come from?. Why don't you create your tables in the Android application?

Related

Offline database inclusion in Android apk on real device

I have a question regarding creating an android application for travel guide. I am creating it offline. I am familiar with the problem that we access the database on the real device. I want an external database file in which the data is already filled. I just want to include this database in my apk and just want to access that database in my phone offline. I am using SLQite database. I had imported db file from assets folder. It works on emulator but not on a real device due to no access to system files.
I think this blog post does what you want to do. I am using this approach in my applications for a while and I am satisfied with it.
It is fast and relatively easy.
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
I have included the db in assets folder and the db file is copied in the path sdcard/Android/data/packagename/test.db on a real device..now I am accessing the db, it works fine on emulator but when I used it on a real device it get crashed.the db is still not working on real device.

database and package location of Android application

I am developing Android application. I use SQLite to store data in user's device. The problem is I don't know where the database is. I also can't locate the package of my application in the device. Usually package can be found at directory Android/Data/com.example.xxx. Can anybody tell me why?
By the way I follow SQLite tutorial from http://www.edumobile.org/android/android-development/use-of-sqlite/
I have checked the code and it doesn't show where the database saved.
I use SQLite to store data in user's device. The problem is I don't know where the database is. I also can't locate the package of my application in the device.
You do not have access to internal storage on a production device.
Usually package can be found at directory Android/Data/com.example.xxx
I have never seen such a directory.
A SQLite database traditionally, on Android 4.1 and below, would be in /data/data/com.example.xxx/databases/. However, you can only get to that directory on the emulator and on rooted devices. And, on Android 4.2 and higher, the path to internal storage depends on the user account.
Your application can use getDatabasePath() to learn where your database is stored (e.g., for logging), and you can copy that file from within your app to external storage (e.g., via a Backup action bar item).

Database created from SQLite Browser not working in device "Android"

My proble is I created a device in sqlite database browser and its work fine in emulator.
but when a try my application to my device it cause force close.
and when I remove the database and create a new one using eclipse it works fine even in my device. But inserting a lot of data in database 1 by 1 realy freakin me out so anyone know a sqlite database browser that also work for device??!
check out this tutorial for using database file in application.
Remember one thing that it only copy you DB file in application that's it.
On real device you don't have permissions to sqlite database. That's why you won't be able to browse database like you can on a emulator.
See this for a work around.
Tool to see android database, tables and data
If you want to create a pre-loaded DB outside of your app and use it in your app later, you will have to put it in your assets directory and then copy it to your apps storage space the first time your app is started.
This is due to the fact that as a security measure, on real (unrooted) devices nothing but your own app is allowed access to that apps databases directory (and certain other ones as well).
There is a good tutorial for creating/copying your own DB outside of the app and copying it to the apps databases directory here.

Where does Android keep SqliteDB of an application runs on a tablet?

I could not find the sqlite db file of the application that I am developing runs on a tablet (not on emulator). Please anyone share with me that where does android keep db file of an application. And how do I export it to the computer? And finally is there any tool that can parse an sqlite expression even if it has no db or table? I mean it will only check the phrase and will say the phrase is available to run or not.
Unfortunately, application's database files are not available on non-rooted devices. You can either use a rooted Android device, or Android standard emulator, or Genymotion (see https://www.genymotion.com) in order to be able to access database files of your app.
It keeps it in a private embedded linux folder that's based on your application name, but that only the userid of your application can access.
There is no way for you to copy that file directly unless you root your tablet. In the emulator, that file is directly accessible, but the emulator is a special case.
That being said, there is a programmatic way to pull out the data from that database and reconstruct it on the SDcard to pull it back on your PC (that solution is not perfect, but at least it's better than nothing).
Nope, You can't access the DB of the device (eithr phone or Tablet) via ADB or any other third party Eclipse plug-in.
This was restricted because of security, but you can access it if you root your Tablet or Phone, which is again most people don't prefer to do.
or you can choose to make the db in sdcard (which recomended when the db is too huge).

Android SQLite path

I am working with SQLite in an App. It writes to the database, etc., with no problem. However, I can not find this new database. I have tried changing the directory with cd /data/data/packageName/databases, but it says "no such file or directory". Also, this database is not found when I click on the File Explorer in eclipse. My logging tells me the database was created and that it is being written to. I think I need to set the path in the shell or something to that effect using adb, but I have no idea how to do that. Can anyone give me some instruction? Also, I am using my phone for development. The database also does not show up when using the emulator.
Thanks very much.
Matt
Matt,
This thread gives a good explanation on why you might not be able to access the data folder on your phone.
Can't access data folder in the File Explorer of DDMS using a Nexus One!
You can still test the Sqlite code though. Just boot up an emulator. The emulator will have no access restrictions. Once it's booted up you can use the ddms tool (located in the tools directory under your android SDK install folder). It has a File Explorer and you can download the files from the /data folder.
Also, I am using my phone for development.
You cannot access the database on a standard Android device except via your own application code.
Your options are:
Do this sort of testing on an emulator, in which case you can access the directory that you are failing to access on the device
Add a database backup feature to your app, that copies the (closed) database to external storage, so you can examine it
Root your phone (leastways, I am under the impression this can help get you to this directory -- haven't done it myself)
The database also does not show up when using the emulator.
Try harder. If you can store data in the database and read data out of it using SQLiteDatabase, then the database file is there.

Categories

Resources