How can I implement ability to attach files from file system to my application. Can I use some libraries, or I should do it myself programmatically? Or I can implement code of other similar application and use them?
File browser:
Link
A sample code for file browser. Or you can just let user input the location into an EditText and let app remember it.
To use external storage(like SD card), please see here
Remember the file location:
Using Shared Preferences
It is a simpler way to save persistent data than SQLite database
Send it to server:
Link
Here is an example of how to use HTTP POST to send to server
Related
I use the internal shared preferences to store key/values on an Android device. I wanted to have a look at this data directly using a file explorer but I cannot find where it is stored physically. Most apps have an own directory on Android/data but there is no folder for my Flutter app.
Do you have an idea where the data is stored locally?
Thanks in advance.
Edit (To make my problem clearer):
I need to access this data from outside app. A user of my app is not able to start the app anymore for some reasons. I want him to send me the internal data for debugging purposes.
So is it possible to fetch the related files in any way without the app self?
SharedPreferences are stored in an xml file in the app data folder, i.e.
/data/data/YOUR_PACKAGE_NAME/shared_prefs/
You can access these from Device File Explorer Tab inside the Android Studio IDE on the right side :
On native android its stored inside the data folder. The path will be something like
/data/data/<your_package_name>/shared_prefs/YOUR_PACKAGE_NAME_preferences.xml
On Flutter projects its stored inside the same folder but with fixed name FlutterSharedPreferences.xml
Something like
/data/data/<your_package_name>/shared_prefs/FlutterSharedPreferences.xml
Edited in response of updated question - 05/01/2023
If your app is relying heavily on sharedpreferences then I don't think there is a way to get it from outside your app. But I have an idea which you can try.
Try this package https://pub.dev/packages/flutter_logs.
This can create log files in file system. If your app is currently crashing after opening you can try to put this log code to write down the sharedpreferences inside the log file. Then you can setup some code to send the logs by email.
But there are few catches in this approach.
You have to set this code in initial screen like splashscreen and wait until this process is complete.
You have to send this updated apk and ask your user to install it.
I suggest you to implement this anyhow as in future you might get stuck in similar situation if you are relying on sharedpreferences.
Hope this helps.
I have an app I want to make for Android. I have decided to store the information I will display in a text file and parse it, rather than a database since the data is so simple.
The info is just two lines of text, a word and a short description of that word. I want the app to get each pair (word, description) from the text file and display it on a card in the app.
I stored the .txt file in Google Cloud Platform Storage and now I need help writing the code to access the file(s) and parse them to use in a Cards UI.
I can find no helpful examples of how to get this file then parse it in the app in a smooth way.
You can use a client library to open the file and read it. For example, the Python client library is at https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/functions
and your code would look like this:
import cloudstorage
try:
gcs_file = cloudstorage.open(filename, 'r', content_type='text/plain')
# process as normal ...
except cloudstorage.NotFoundError:
pass
Sample Java client code is at https://cloud.google.com/storage/docs/xml-api-java-samples
I have an application that stores data in SQLite db. I've implemented export of this data to external file (in json format) with custom file extension. Also I have an activity that starts when user opens my file and saves it back to SQLite.
I don't want to backup my db, I'm exporting a part of data to be used by another users.
My next goal is to make sharing this data via Bluetooth (export it to Dropbox / send via email). I want it to look like described in this tutorial: http://developer.android.com/training/sharing/send.html but I doubt that this tutorial is what I need.
I don't want users to export data to file and then send this file via Bluetooth, I want them to share data directly from my app.
I looked at FileProvider. I'm confused with insert, update and other methods so I'm not sure this is the right choise.
I looked at Sending Binary Content tutorial but I don't know how to create intent properly and how to save my temporary file for sharing.
Please, describe the way to share this type of data or give me links to examples. Thanks!
P.S. sorry for my English
In my application I allow users to share files with external apps by using content provider. My files are encrypted so before I can share one of those files, I need to decrypt it and store it in application internal storage. After that I implemented custom content provider that can point to the file by using a given URL and return ParcelFileDescriptor instance.
For security issues I would like to remove the file from internal storage after external application has used it, or user canceled operation.
EDIT: The external application that I am sharing file with is a 3rd party application.
So my question is:
When should I remove the file, or do you know of any event that I can listen to or a handler that I can attach to the file?
Thank you for all you responses.
Side question would be:
Do you know of a way where I wouldn't have to store the file on internal storage, but rather send it directly as a stream to the external app?
The answer to my question is to use pipes ParcelFileDescriptor.
Code is described in The Busy Coder's Guide to Android Development from CommonsWare.
The solution is based on:
https://github.com/nandeeshwar/Pfd-Create-Pipe
Actual solution that I managed to implement is:
https://github.com/commonsguy/cw-omnibus/tree/master/ContentProvider/Pipe
If it is your external application, you could leave an encrypted file and pass the key in an Intent. If it is a 3-rd party external application, you have to find out what that application can accept.
You might also read about services -- maybe they provide what you want.
As to "when", I'd suggest launching a clean-up task in onResume(). (Unless you decide to use a service.)
I have a compressed(.gz) xml file on my server. I need to read that file and get the information to store in the SQLite DB
Have to access the server via HTTPS.
"https://SERVER_ADDRESS/PATH/employee.gz"
Normally when I log in to the server to the folder where these xml files are stored, it asks me for user name and password. So in code how to handle this.
I searched but didn't get the exact one I need. Great if someone Can help me in this. Thanks.
Depending on how you are reading from HTTPS, GZIPInputStream might work. http://developer.android.com/reference/java/util/zip/GZIPInputStream.html
Also, look at http://developer.android.com/reference/org/apache/http/auth/UsernamePasswordCredentials.html for accessing password protected directories with http.