I am building an Ionic 4 App + PouchDB, I have built the app by executing the command ionic cordova run android and for a few days, it works well. Recently though, the app just won't open anymore and I have no idea how to check what went wrong.
Prior to this, whenever something went wrong in the app, I am able to check it using the chrome://inspect. However, with the app not being able to open at all, it's impossible to check the cause of the problem since I am also unable to check using chrome://inspect.
When I tried to run it using ionic cordova run android -l, I get the same result, which is the app loads and closes a few moments later, and I'm still unable to get into chrome://inspect.
I had a hunch that it has something to do with PouchDB. The app starts to behave this way when the storage is almost reaching 200mb. Upon reading the PouchDB FAQ, it's stated;
In PhoneGap/Cordova, you can have unlimited data on both iOS and Android by using the SQLite Plugin.
But I am already using the SQLite Plugin for PouchDB, I have used cordova-sqlite adapter for my PouchDB too.
Below is an example of line in my code:
this._userdb = new PouchDB('user.db', { adapter: 'cordova-sqlite'});
With the app being unable to open, I'm out of ideas on how to retrieve the data stored inside PouchDB since I can't even get into the chrome://inspect at all (I can't see any console.log() for the stored data).
I feel like clearing the app data would allow the app to be opened as how it used to be but I really need to do a backup of the data stored inside PouchDB but I really have no idea how other than getting the console.log() of the data.
Is there any other way I can access the data stored inside the PouchDB to do the backup?
After many failed attempts to figure out how to retrieve the data stored inside PouchDB , I found one solution which is to pull the APK and extract the backup file.
By referring to this article, open CMD and shell into your device by;
adb shell
Provided that you know the app's package name, proceed to pull the APK by running;
adb backup -noapk com.app.your.package.name
**Note: Some devices like Samsung Galaxy stock Android 11 requires password to 'Backup my data'
Once pulled, you will find a backup.ab file and you need to extract this file. At this step, as a Windows user, I was unable to use the openssl method. I get an error using Python too.
But I found a solution that worked well for a Windows user. According to that solution;
Download Android Backup Processor
Go into the directory android-backup-tookit\android-backup-processor\executable (this directory should have a abp.jar file
Copy your backup.ab into this directory.
Open CMD, and run;
java -jar abp.jar unpack backup.ab test.tar
If the device was required password during the backup process, you will be asked to enter password. Enter the same password you provided during backup. Be sure to read the README for further details.
Once done, you will find test.tar file in the same directory. To view the file, simply extract it. The databases created inside the app should be in \test\apps\com.yourappname\f. The sqlite databases files can be viewed using DB Browser for SQLite.
Related
Do you know if there is a way to connected SQLite Studio (or similar) to the database via adb (emulator for Android), so I can see graphically my data via the laptop?
Thanks in advance
Actually you can use DbAndroid plugin (it's free, GPL'ed) that is shipped with SQLiteStudio (3.0.7). It will let you to connect to your android database without pulling or pushing the database file from/to an emulator or a device. It makes direct connection to the database in your application. Any changes to database made in SQLiteStudio will immediately be reflected in your running application.
Long story short - you add a jar file to your project as dependency, add few lines to inid/deinit the connector, then you add your database in SQLiteStudio and use it just as any other database.
There's a full manual on how to do it on SQLiteStudio's wiki page about this plugin: http://wiki.sqlitestudio.pl/index.php/DbAndroid
There's also a video demonstration on how to do it (also at that site). It's a bit too much to paste all of it here.
If you have any further problems with it, I'm happy to help (author here). You can also ask on SQLiteStudio's forum - I watch it often.
You can use Sqlite Studio to see your data: http://sqlitestudio.pl/
For internal storage you can get the database via adb:
adb pull /data/data/app_name/databases/db_name yourpath
If your database is in external just open it with Sqlite Studio.
I have developed an Android app using Appcelerator Titanium. This app will create a file in applicationDataDirectory and install a database as well.
If run on emulator, I can locate those files using "adb" command. But how about on Android device? Can I use the "My Files" app to view those file I created? (since I can see files created by other application there.)
Moreover, I expect once I removed the app on device, it will automatically remove the related files and database. Is that true?
Because I found that even I removed the app from the device, the database seems left behind. I can tell because after deleting app and re-run on device(from Titanium), it show previous data.
I am using Ti SDK 2.0.1GA2, Android Runtime V8. And using Samsung Galaxy Tab for testing.
Thanks in advance.
Application Private Data files are stored within <internal_storage>/data/data/<package>
Files being stored in the internal storage can be accessed with openFileOutput() and openFileInput()
When those files are created as MODE_PRIVATE it is not possible to see/access them within another application such as a FileManager.
On Android 4.4 KitKat, I found mine in:
/sdcard/Android/data/<app.package.name>
Use Context.getDatabasePath(databasename). The context can be obtained from your application.
If you get previous data back it can be either a) the data was stored in an unconventional location and therefore not deleted with uninstall or b) Titanium backed up the data with the app (it can do that).
You can get if from your document_cache folder, subfolder (mine is 1946507). Once there, rename the "content" by adding .pdf to the end of the file, save, and open with any pdf reader.
This is a simple way to identify the application related storage paths of a particular app.
Steps:
Have the android device connected to your mac or android emulator open
Open the terminal
adb shell
find .
The "find ." command will list all the files with their paths in the terminal.
./apex/com.android.media.swcodec
./apex/com.android.media.swcodec/etc
./apex/com.android.media.swcodec/etc/init.rc
./apex/com.android.media.swcodec/etc/seccomp_policy
./apex/com.android.media.swcodec/etc/seccomp_policy/mediaswcodec.policy
./apex/com.android.media.swcodec/etc/ld.config.txt
./apex/com.android.media.swcodec/etc/media_codecs.xml
./apex/com.android.media.swcodec/apex_manifest.json
./apex/com.android.media.swcodec/lib
./apex/com.android.media.swcodec/lib/android.hidl.memory.token#1.0.so
./apex/com.android.media.swcodec/lib/libcodec2_soft_common.so
./apex/com.android.media.swcodec/lib/android.hardware.graphics.mapper#2.0.so
./apex/com.android.media.swcodec/lib/libcodec2_soft_vorbisdec.so
./apex/com.android.media.swcodec/lib/libcodec2_soft_h263dec.so
./apex/com.android.media.swcodec/lib/libhidltransport.so
./apex/com.android.media.swcodec/lib/libcodec2_soft_h263enc.so
./apex/com.android.media.swcodec/lib/libcodec2_vndk.so
./apex/com.android.media.swcodec/lib/android.hardware.graphics.mapper#2.1.so
./apex/com.android.media.swcodec/lib/libmedia_codecserviceregistrant.so
./apex/com.android.media.swcodec/lib/libhidlbase.so
./apex/com.android.media.swcodec/lib/libcodec2_soft_aacdec.so
./apex/com.android.media.swcodec/lib/libcodec2_soft_vp9dec.so
.....
After this, just search for your app with the bundle identifier and you can use adb pull command to download the files to your local directory.
ALL,
I wrote a simple android app that uses database.
When I execute it everything is OK. However when I switch the phone to mount mode I can't find the actual *.db file.
I am trying to execute following:
cd /media/
find . -name *.db
I also tried to search for the database file without success.
After playing a little with SQLite database browser I know that I need to save the file after creation.
Is there such a function in Android API?
Thank you.
If your app uses a database, it will be placed in the /data/data/<your-apps-package-name>/databases directory on your phone. To see it on the phone, I believe you need root privileges.
You should be able to pull the database locally to a connected machine which has adb installed on it. Or you can use ddms with Eclipse to pull the data to your machine.
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.
Is there a way for an Android user to browse the SQLite databases on his/her phone and view the data in the databases?
I use the SoftTrace beta program a lot. It's great but has no way that I can find to download the data it tracks to a PC.
The database for a specific app lives in /data/data/[packagename]/databases
The packagename is the package you define in your manifest, for instance /data/data/org.vimtips.supacount/databases/counts.db.
You can view it with adb shell and type sqlite3 /data/data/org.vimtips.supacount/databases/counts.db
Or you can pull it from the device to look at it with a third party utility, with a command like adb pull /data/data/org.vimtips.supacount/databases/counts.db ..
This assumes you have permission to view the database, which you might not have if you didn't write the app yourself... but in that case, is it actually a programming question?
If you are using Eclipse, you can use a plugin called 'Questoid SQLite Browser' to browse the SQL Lite Database on your Android emulator:
Install the plugin
Restart eclipse
Start your emulator
Switch to DDMS
Open database with plugin (as #synic mentioned previously, the DB is located here e.g. /data/data/my_project/databases)
Here is a more detailed tutorial: http://www.tylerfrankenstein.com/browse-android-emulator-sqlite-database-eclipse
Here is the free method that worked for me on a phone that is not rooted. Credit goes to this SO answer.
Use adb backup -f backup.ab -noapk app.package.name
On Windows download the Android Backup Extractor jar found on SourceForge here, then run java -jar abe.jar unpack backup.ab extractedbackup.tar. On Linux you can follow the dd instructions from the answer I gave credit to in the beginning.
Download SQLite Database Browser from SourceForge here, then open the db file contained within extractedbackup.tar.
Personally, to make this process easier, I first added adb to my environment PATH. Then I made a backup folder where I store all of the files mentioned above. This keeps me from having to cd (change directory) all over the place.
The Questoid plugin appears to cost $9 and requires registering. Another alternative on Windows is to download the open-source public-domain SQLLite Browser (link below) and then pull the database from the phone. In Eclipse you can do this from the File Browser, going to the /data/data/[packagename]/databases directory on the phone or emulator, and clicking "Pull a File From The Device" in the top right. Save the database locally, then open with the SQLite Browser.
http://sourceforge.net/projects/sqlitedbrowser/
Actually the most available (yet still hacky) way of getting "live" results from a database while developing on emulator that I found is this:
Create a script to pull the database from emulator, something like this
#!/bin/bash
ANDROID_HOME=/path/to/sdk
ADB=$ANDROID_HOME/platform-tools/adb
REMOTE_DB_PATH=/data/data/com.yourpackage.name/databases/your_db
LOCAL_DB_PATH=.
while true; do
echo copying DB...
`$ADB pull $REMOTE_DB_PATH $LOCAL_DB_PATH`
sleep 3
done
Run it.
Install SQLite Manager plugin for Firefox
Open your local copy of the database (which is constantly overridden by the running script from step 1)
Enter your SQL:
Select File->Reconnect
Click Run SQL
The key trick is that reconnecting does not reset SQL entered on step 4 (as it does, for example, in SQLite Browser), so you can repeat steps 5,6 to see "live" results from your android database.
Note that this only works for emulator, it won't work for a real device (even a rooted one).
You can view you database from your app using this library . https://github.com/sanathp/DatabaseManager_For_Android
With this library you can manage your app SQLite database from you app itself.
you can view the tables in your app database , update ,delete, insert rows to your tables
Its a single java activity file ,just add the java file to your source folder.When the development is done remove the java file from your src folder thats it .
It helped me a lot .Hope it helps you too .
You can view the 1 minute demo here : http://youtu.be/P5vpaGoBlBY
If you were lucky enough to get IntelliJ Ultimate then you can plug the device in, open 'Database' tab on the right, click +, select SQLite. The rest is trivial.
One thing to keep in mind with it is that you have to keep clicking "Synchronize" button on the database (or on selected table) to see the changes made externally, which is very annoying.
See this answer. You can use Stetho library from Facebook and then just browser you database from Chrome :)