android - prompt user for path/filename - android

I want to ask user to select a file to open from external storage and receive it's path. Preferably I'd like to avoid excesive coding and use some standard method (well known, system-provided intent or similar).
Said file is to be SpatiaLite db file (*.sqlite), so it won't show in Gallery.

Unfortunately there is no Android native file picker, but you can get an open-source one to add in your project, then modify it to fit your needs. Check out this SO question for a good start.

I would also suggest that Android file pickers have intents that you can feel free to use. Unfortunately if the user does not have the proper apps on their device, your intent will not succeed. If this happens, you can always direct the user to download the app. Alternatively, you can check if the file picking intent will succeed (see this advice), and use the standard file picker if so (many users have ASTRO, for example, which I think has an intent you can use), and you can fall back on something included in your app, this will make for a perhaps nicer end to end user experience across apps on their device.

Related

Android - how prompt user to choose an external program for rendering a file

I am writing a program for Android which has PDF / ODT file with instructions (yes, those are complex). Actually, I am planning how to do it... So, let's say, a user taps on menu entry "View Instructions" and he should get a prompt which asks to choose an external app for viewing the file (I assume that viewing PDF/ODT file inside my program is extremely complex task, so I find it acceptable to delegate it to another app), - and chosen program pops up with opened file for viewing. How do I implement such behavior?
I have very limited experience at programming Android, I have written a program which interfaced with camera. From that time I remember that I called something like Activity... or Intent... I don't remember. Anyway, it opened Android-specific Camera-related system application. It is almost what I'd like to achieve.
So, how do I open a file in some 3rd party program from my code, giving user a choice?

Android 11: How/where to write mixed media files that should survive uninstall

I am writing a specific use-case camera app that targets Android 11. When I hit record I would like to create a new directory somewhere (with a name based on the timestamp etc) that contains the resulting video as well as a whole heap of other custom YAML/JSON/CSV files that also get written during the recording process (belongs logically to the "output" of the recording).
I would like all of the generated files to survive an app uninstall/reinstall as I do not want to risk users losing everything they've ever recorded if they uninstall the app. How do I do this with the new scoped storage changes etc in Android 11?
Looking at the overview here, I can see that:
App-specific files, App preferences and Database are clearly not suitable as amongst other things these files do not survive an uninstall
Documents and other files uses the Storage Access Framework, but this is not suitable because it requires a system file picker every time you want to write something. This would disrupt the flow of recording/user experience, and no camera app works like that.
Datasets/BlobStoreManager (here) also is not appropriate for my use case.
MediaStore API looks like it should be the one, but it can't seem to do what I want in terms of producing a whole directory of outputs, including custom YAML/JSON/CSV text files, that all belong together. My aim is that the user at all times can simply go to the file explorer, navigate to the appropriate folder, and just copy out the folder(s) with the recordings to their computer or whatever, to save/view the data. Even MediaStore.Files does not seem to guarantee you can actually do that if your app is using scoped storage.
The only option that seems to be left is using MANAGE_EXTERNAL_STORAGE and putting the data wherever I want in the home directory, but that seems like a bit of an extreme permission to be asking for just in order to be able to save some text files along with my produced videos. Also, that permission is Android 11 specific. If I want to support older Android versions, what would I need to do?
What is my best choice here? Is there an option I've missed?
but this is not suitable because it requires a system file picker every time you want to write something
No.
Use ACTION_OPEN_DOCUMENT_TREE to let the user pick a document tree. In there, you can create your own sub-tree and put your own documents into that sub-tree. You do not need the "system file picker" for anything beyond the initial ACTION_OPEN_DOCUMENT_TREE request itself. And the resulting documents will survive an uninstall.
You can create your own directory in a public directory like DCIM, Pictures, Music or Movies with classic File methods.

open specific files from within android app

As part of an app I'm writing, I need an ability to look for specific files, like .doc or .rtf, from within the app. After finding them, the app will store their adress or something like that, so that they could later be opened when necessary. The app wouldn't open them itself, it will use a different app for that. So, all I'm looking for is a way to browse for those files from within my app.
As i understand you need to find files with given extension. For this approach you can use FileFilter. Check this answer.

How to write an Intent to display file with only desired extensions in Android

I am developing an android app that encrypts/decrypts file.
Once a file is encrypted, its extension changes to filename.encrypted ( here filename is itself a fully qualified filename like hello.pdf, so the encrypted file becomes hello.pdf.encypted).
I have intregrated a file chooser intent in my app, so that user don't need to open a third party intent to choose the files.
My problem is, while user selects to Encrypt a file, he should not be allowed to choose files that are already encrypted i.e. having the extension ".encrypted" and when they are trying to Decrypt a file they should only see the files with the extension ".encrypted".
I have seen a lot of file chooser intents like (https://github.com/iPaulPro/aFileChooser) and (http://code.google.com/p/android-filechooser/) but none have the ability to customize the viewable/selectable files. I read a post (Android file chooser) that says, it cannot be done, but I have seen apps that have implemented this feature.
I am need of help in some resources or links that shows me how is that possible to achieve. I strongly believe the functionality is possible.
Besides, I would also like my app to recognize the extension ".encrypted" when viewed from a third party file manager. I believe that is possible by indicating it in the Android Manifest, but I failed to make it possible. I read this post: Register new file type in Android but could not do it.
Looking for some help here.
I found a library https://github.com/Kaloer/Android-File-Picker-Activity for the thing I wanted to achieve.
They have given us provision to specify allowed extensions using putExtra in the intent.
May be it would be useful to others with similar problems.

How to save APK file of my own app in sd-card and share it via bluetooth? (only by using code and intent)

Here, in my country, there is no access to Google Play. I have written a FREE useful app for my people, and some days after its release, I concluded that the best way to make it more reachable, is to share it's APK file via bluetooth (because sharing files by bluetooth is very popular here!)
Now, the problem is:
How can I (by code) save a copy of the running APK file in sd card, and then use some intent to prepare the file for sharing by
bluetooth?
Unfortunately, I haven't yet tried any code, because simply I don't know where to start from.
So just the starting points or some hints are very welcome!
EDIT: Some of my users, are more technical and know that they can use a FileManager/Bluetoth Sharing app to send the APK to their freinds, but I want anyone be able to simply share the app by just clicking a button in the app, even if they are rookies or haven't any file manager on their device.
If you do a standard ACTION_SEND Intent using the installed location of your app, and make that Intent explicitly targeted to Bluetooth, you can do this. You can see how here:
Bluetooth File transfer on Android(even restricted types)
By code seems to be overkill in your situation. Maybe just using a file/app sharing app over bluetooth would be enough : http://www.guidingtech.com/10346/transfer-android-apps-between-phones-bluetooth/

Categories

Resources