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."
Related
When I fresh install app, I notice most of the app will have a folder created in Internal Storage > Android > Data > com.example.package folder. For example its facebook app it will be something like com.facebook.xxxxx.
However, one of the project I involve recently, I notice there is no such app folder in the path Internal storage > Android > Data > (No packege folder).
In what scenario it won't create an app folder in the above path ? Because most of the app I debug run via android studio or install via apk file...Always have one app folder in the above location by default.
Because I want to write below file into getFilesDir(),
File file = new File(activity.getFilesDir(),imageFileName);
By using getFilesDir(), written file will go into Android > Data > Package folder > Files folder, most of the installed app have a package folder path in Android > Data > (Here). Today I realise one of the project I am doing now, it doesn't create such package folder. So, when I use getFilesDir() , those files will still be stored and created inside the mentioned path but it is invisible? Or Those files I create using getFilesDir() won't be created? Because as I mentioned this app doesn't create a package folder. Do I have to use makedir ? If yes what will be the checking ? if(!activity.getFilesDir(). exist())
File file = new File(activity.getFilesDir(),imageFileName);
//getFilesDir() normally is package folder Android > Data > (package folder*) > Files
I have tested and find out that if phone is having internal storage only (Not support SDCard) or maybe phone support external storage but don't have SDCard insert. App folder in this path by default won't be created (Android > Data > [App folder]), until I called (getExternalFilesDir(null) , "Example1") check its exists() and makedirs() if it doesn't exist, finally the app folder is created with a folder Example1 in this path Android > App > com.xxxxx.myapp > files > Example1.
However, why some sample app I create I never call getExternalFilesDir(null) or any File writing storage path but by default I can find my sample app path in Android > App > [Here].
Some app folder won't be created by default but until getExternalFilesDir(null) check exist and mkdirs then it become exist and created. Some app folder will be created when app is installed by default. How Android determine if the Android > App > App folder should be created and visible or created and make it invisible??
It makes me confuse. Some app will create app folder, some app wont create it by default when app is installed. Let's assume both app never call any File path create method. Just a very sample app I run using latest Android Studio to test something, it created package folder. The big project app is using old gradle settings and almost 5 years ago, the app by default won't create package folder until I call File(getExternalFilesDir(null), Example1) check if it exists and it doesn't then mkDirs(), package folder become created and visible.
How SY MY told you need to check if phone is having internal storage only (Not support SDCard) or maybe phone support external storage but don't have SDCard insert. App folder in this path by default won't be created. And how he checked you shoud make if statement. So... you can paste this code in your project:
File file = new File(getExternalFilesDir(null),fileName);
if (!file.exists()&&file.mkdirs()){
File file1 = new File(getFilesDir(), fileName);
}
fileName it is a String varable with txt foramt:
private String fileName = "list.txt";
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.
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?
I want to open my database file using "Questoid SQLite Manager". When I'm trying to do that a message says: "Select db file in File Explorer, and open it in SQLite Manager..."
As I've searched about this error, I've find that the database must have .db extension. now my database name is mydb.db and it's running on emulator.
Most of topics about this error are referring to .db extension and root permission as I've seen in these topics:
Not able to open database file in SQLite manager plugin for eclipse?
https://stackoverflow.com/questions/19177467/not-able-to-open-the-db-file-with-questoid-sqlite-manager-browser
Why I can't see DB structure by SQLite Manager in file explorer
What else I should do about it?
I had the same problem with "sqlitemanager": only .db-Database files are accepted.
This is the solution:
Download this Questoid SqLiteBrowser: http://www.java2s.com/Code/JarDownload/com.questoid/com.questoid.sqlitebrowser_1.2.0.jar.zip
Unzip and put it into eclipse/dropins (not Plugins)
You can use http://sourceforge.net/projects/sqlitebrowser to open your database file.
did you try to open it using firefox.
there is a plugin needed for it to do so
check this