After creating a database file and tables in android studio.
I went to the /data/data directory(at the android device monitor) and the only directories I see are named 'con',
and not my package name.
I know there are three options:
1. I can't get the database directory because I'm working with the emulator.
2. To specify a new directory to put this file in(I don't know how).
3. To re-install android studio(I doubt it will help)
What can I do tot fix it?and what is the problem?
Related
I want to know the correct steps to keep local saved data after app update.
I confirmed the following old question, but I can't solve the issue.
Save app data in kivy on Android
I tried the following.
1-1:I made android APK with buildozer(command:buildozer android debug). 1-2:And execute 'store.put' method using 'kivy.storage'. then 'hello.json' file was created in the './' directory.
https://kivy.org/doc/stable/api-kivy.storage.html
1-1:'./' directory in APK ver.1
main.pyo
1-2:'./' directory in APK ver.1
main.pyo, hello.json(created)
2-1:I made android APK ver.2(same app name as 1.APK). 2-2:After installing in update mode, execute only 'store.get' method using 'kivy.storage'. then method failed because 'hello.json' file was automatically deleted with app update.
2-1:'./' directory in APK ver.2
main.pyo(changed from APK ver.1)
2-2:'./' directory in updated APK
main.pyo(ver.2)
I tried changing the output location of the 'hello.json' file but it made no sense.
e.g. './data/data/[app_name]/files/hello.json' and './data/data/[app_name]/shared_prefs/hello.json'
How can I update my application?
Everything in the default current directory, which is named app, is deleted and replaced on app update. You can place persistent data in the directory above this, i.e. ../, and it should stick around between updates.
You can also use your app's external storage directory, using pyjnius to query the Android API for its location, but I don't have code for that right now.
This isn't especially well documented, I'll try to improve it.
An empty database file with the same name exists BEFORE we copy it from the assets folder.
android.database.sqlite.SQLiteException: no such table:
This error message is legitimate because an empty database exists in our data directory with the same name. Although we have not copied it yet.
How is our database file being created?
Why does it exist even if we have not called or instantiated our Database Helpers?
Using the same SQLiteHelper classes for all previous versions with no issues.
Running on Android 9 Pie causes this error message after a clean install of our Android app that uses an existing database in the assets directory. Normally when this file does NOT exist in the data directory it is copied then opened.
Checked and rechecked, the file exists BEFORE our call to move it from our assets directory.
When checking the Android 9 Pie data directory, our SQLite database file already exists. This is after a new install AND clearing cache & data
To repeat what we are seeing.
Settingsā¦ Apps & Notifications
Select our app
Storage
Clear Cache + Clear Storage
Uninstall the app.
Launcher Activity "SplashActivity" onCreate()
String mName = "myawesomedatabase.db";
String mDatabasePath = this.getApplicationInfo().dataDir + "/databases";
File file = new File (mDatabasePath + "/" + mName);
Log.i("DATABASE", "##### SplashActivity.getData() " + mDatabasePath + "/" + mName);
if (file.exists()) {
Log.i("DATABASE", "##### SplashActivity.getData() FILE EXISTS!!!");
}
Repeating the above and NOT uninstalling the app, copies the file properly. It is ONLY on new installations.
We have confirmed we are not hardcoding the data directory. Researching this we learned that the database directory has changed.
From: /data/data/com.___._____/databases/
To: /data/user/0/com.____.____/databases/
Referencing this article that helped this discovery.
Android P - 'SQLite: No Such Table Error' after copying database from assets
Work around:
Clean install of the app.
Wait for crash
Settings... Apps... Specific App... Clear Cache + Clear Storage
Run app again
Success, database does NOT exist in data directory, then the app copies file from Assets Directory with no issue.
No stupid questions?
But man I feel dumb when it was an easy answer.
Perhaps taking the time to ask here made us look harder.
Android P has auto restore from backup. Even if you do not have a copy of the app installed. So a corrupted file was being restored from backup.
Android P steps to correct (at least in development environment)
Settings...
System
/ Advanced
Backup
App data
Turn OFF Automatic Restore
Discovery came after finding out it worked on AVD with Factory reset. However development devices with different app versions experienced the same issue.
Im trying to create a sqlLite db. This code works and create the db and allow me do insert and select.
string dbPath = Path.Combine(
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
"ormdemo.db3");
//dbPath = "/storage/emulated/0/DCIM/ormdemo.db3";
var db = new SQLiteConnection(dbPath);
db.CreateTable<Stock>();
Right now the dbPath returned is:
"/data/user/0/MyFirstGPSApp.MyFirstGPSApp/files/ormdemo.db3"
But when I use a sqlLite Manager to try open the db I cant find the folder /data/user
Where is that folder /data/user?
The sqlLite have the option to open "APP" databases, but when try to select MyFirstGPSApp say need a root device.
The starting folder for sqlLite is /storage/emulated/0 and have a sub folder /DCIM
So I try to use a folder I can see ... like /storage/emulated/0/DCIM/ormdemo.db3 but then the new SQLiteConnection(dbPath) give me this error.
SQLite.SQLiteException: Could not open database file: /storage/emulated/0/DCIM/ormdemo.db3 (CannotOpen)
Do I need special permision to write in /DCIM folder?
Ok, there are three questions in your post. Before answer your questions, I think some pictures are necessary.
P1:
P2:
Like #Yogesh Paliyal has said, you need File Explorer to see it. If you also want to see it and you don't want to root you device, please follow me: Visual Studio->Tools->Android->Android Device Monitor->select one simulator from Devices column->File Explorer. I suggest you create a simulator which Api is below 21, because the higher also can't see the file. I am using 19 to see the files.
And I think you should read this firstly.
Ok, let's see your questions:
Where is the app Personal Folder path?
In android, there are two folder: personal/internal folder and public/external folder, here is official document.
Personal/Internal Folder path:
/data/data/package name/shared_prefs: SharedPreferences
/data/data/package name/databases: Sqlite
/data/data/package name/files: Api:getFilesDir()
/data/data/package name/cache: Api:getCacheDir()
/storage/sdcard/Android/data/package name/files: Api:getExternalFilesDir()
/storage/sdcard/Android/data/package name/cache: Api:getExternalCacheDir()
Public/External Folder path:
In /storage/sdcard folder, only Android folder is personal/internal folder,so /storage/sdcard/DCIM, /storage/sdcard/Music,etc, all of them are public/external folder: Api:Environment.getExternalStoragePublicDirectory(String type)
Where is that folder /data/user?
From P1, you can see the ->/data/data/ is behind of /data/user/0, so the folder /data/user/0/MyFirstGPSApp.MyFirstGPSApp/files/ormdemo.db3 is /data/data/MyFirstGPSApp.MyFirstGPSApp/files/ormdemo.db3 actually.
Do I need special permision to write in /DCIM folder?
Personal/Internal folder doesn't need permission, public/external folder need permission.
In /storage/sdcard folder, only Android folder is personal/internal folder, so you need permission:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> or <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> or both.
You can't see directly from mobile without root permissions.
Try using Android Studio's File explorer feature.
Why is it when I install ionic-box (for Ionicframework) it's not syncing in my folder?
I added this line
config.vm.synced_folder "projects", "/vagrant_projects"
to Vagrantfile but it's not working. i still need to create manually the folder vagrant_projects in home/vagrant directory which I thought will be create automatically when creating/installing ionic-box.
I already added a new project inside vagrant_projects but i noticed it is not reflecting in the host folder projects.
BtW, I created the folder projects inside the directory where i extract the Vagrantfile.
Here's my reference: http://www.sitepoint.com/ionic-box-vagrant-configuration-hybrid-mobile-apps/ and http://java.dzone.com/articles/getting-started-building-0
config.vm.synced_folder "projects", "/vagrant_projects" will create vagrant_projects folder at / not home/vagrant. So the path of your folder vagrant_projects will be /vagrant_projects not home/vagrant/vagrant_projects.
Your configuration is correct just login to your vm via vagrant ssh and execute following command
ls /vagrant_projects
you should be able to see your synced data now.
vagrant tutorial
I wrote a mobile application ( AIR ) which storing some strings into a SqlLite database.
It is external database file, which shall reside in a sub folder of the main application folder.
So far everything works flawless while debugging on the PC, but when i am exporting the application into .APK file the result package does not contain the database, neither the database folder.
how to add the database folder and the database file into the result android package ?
In Flash Builder, when exporting a release build; switch over to the "Package Contents" tab and select your database file / database directory in the "Package Contents."