From an Android app, I like to install an apk file from a web server. This apk file contains an update for the app.
All tutorials do this in two steps:
1 Download the file and save it to the phone's sd card memory.
2 Create a new Intent(Intent.ACTION_VIEW) and run the method setDataAndType(Uri.fromFile(new File(".... of this intent.
However, since Android Nougat, you get into trouble with permission to access the SD card memory. There are (complicated) solutions for this problem.
My question: is there a way to create an Intent, which gets a web URL as source for the apk file. Something like intent.setDataAndType(new URL("http://....")
This is easy for the programmer and it provides as clear interface from the program to the Android system
is there a way to create an Intent, which gets a web URL as source for the apk file. Something like intent.setDataAndType(new URL("http://....")
Not as part of standard Android. The app installer knows about the file scheme, and on Android 7.0+ it knows about the content scheme. It does not know about the http scheme.
All tutorials do this in two steps... Download the file and save it to the phone's sd card memory.
Few tutorials do that. Most download the file to external storage, which is not the same as removable storage. On Android 7.0+, you also have the option of downloading to internal storage and using FileProvider (or the equivalent) to make it available via a content Uri.
Related
I'm loading HTML from the downloads folder on Android and showing it in a WebView. If the HTML there are some built-in HTML files that are in the assets for the app so I copy them to the Downloads folder and load them from there. These load just fine. If I try to load an HTML file that was copy into the Downloads folder via ADB it says ERR_PERMISSIONS_DENIED in the WebView. When adb shell and look at the file owners and privileges they are all the same so I can only think that Android remembers that my app put some of the files there and loads those but not the others?
I have android:requestLegacyExternalStorage="true" in my manifest and I'm requesting Manifest.permission.READ_EXTERNAL_STORAGE and Manifest.permission.WRITE_EXTERNAL_STORAGE when the app loads. What else do I need to do to make this work?
For context:
I'm working on an app that connects to a custom BLE device and allows users to control various demo applications. We want the demos to be written by UX folks on our team using HTML and JavaScript so the app. To support this, the app has a WebView that just loads the index html. The UX folks need to be able to make changes and try new things. The easiest way for them to get it on the phone is to put them in the Downloads folder. I the app creates a folder in Downloads and copies any built-in demos from assets to that folder and then loads them from there. That way it can auto-detect any new demos the UX team adds.
Android remembers that my app put some of the files there and loads those but not the others
On Android 11+ (and perhaps 10), this is absolutely the case.
What else do I need to do to make this work?
The simplest solution is to stop using Downloads/. Instead, use the directory available as getExternalFilesDir(null) on Context. You have full read-write access there, and your designers can drag-and-drop files to that directory (Android/data/your.application.id/files/) if they're using a USB cable to transfer files from a desktop or notebook.
I am confused with the new app storage system in Android. I am not sure where my use case falls under and I need your help in telling me the right approach for this
My app captures images and generates pdf documents. Prior to Android 10, I used to store them in an app directory where the user can easily navigate to them through other files browsing app (like Files app on Samsung). In addition, these files can be accessed from within my app (so essentially read and write).
With the new storage, I am not sure how to accomplish the same thing. If I use the internal storage then user can't see them. If I use the media approach, well it seems it is only for Audio/video plus they will not be organized in a folder like I have them organized.
Am I missing something? How would I solve this problem?
Thank you
On an Android 11 device you can store your files in a subdirectory of the public Documents directory.
You can do that using classic File means or the media store or SAF.
Other apps can see them using SAF or the media store. Or with classic file means when requested all files access.
The user can see them using the default Files app on the device.
For my app I want to send the user a text file of data on an e-mail which they save in the download folder on their Android device.
The app will then pull the data from that file and use it in the app. In the desktop version URLLoader works fine with the file copied into the app source directory, but that method does not work on an Android device.
Storage permission is set.
I have tried using the Filestream method and manually copying the file into the app directory on the device, but that does not seem to work.
Ideally I want to be able to set path for the file to the device's download folder so that the user experience is as simple as it can be.
And before you ask, usage will be on wifi only tablets with questionable wifi access - sending e-mails with the file upfront is the only reliable way to handle this.
Thanks for any suggestions.
Adam
In mobile devices the File.applicationDirectory , is a read only folder, try to use File.applicationStorageDirectory
https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html#applicationDirectory
https://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7fe4.html
I have a document file stored in my application's data folder, which is a kind of private folder to the application. It is a .doc file. I have doc viewer application installed in the device. Now, how can I open the file with the Action_view intent. As the viewer application can't access file stored in my application data folder, it is throwing an error saying file can't be accessed. I have no interest to copy the file to phone public folders like sdcard. Is there anyway to open that doc file. Any clue on embeded apk in android.
Thanks & regards,
Suman
You can't do this directly. Either copy the file temporarily to the SD card (external storage) or set permission temporarily to WORLD_READABLE. There are no embedded APKs in Android, but if the viewer is available as library you can include it in your app. Of course the problem with changing permissions temporarily is that you don't really get notified when the user has finished viewing it, etc.
The whole thing begs the question: why is it a private file if it needs to be viewed by third party applications? If it is meant for the user of the device, there is not much point in hiding it from them...
The problem is this:
I make an internet connection to some url
and receive an HttpResponse with an app_example.apk.
Then I want to create a file (an .apk) in the sdcard with this data
so that this downloaded application can be installed later.
How can I convert the HttpResponse to an .apk file?
Be aware of that you need the WRITE_EXTERNAL_STORAGE permission in your application, but you can just write to the sdcard then. Every content, every filename you wish. Installing is, however, another thing.
If you are trying to install another application (like an add-on or additional data), you should publish the add-on on the market, and use intents to ask the market to take over the download and install process of the additional data.
Installing to the SD card can't be done via the API's, as far as I am aware, you can only install applications to the device's internal memory. Downloading additional data should either be done via the market as an APK, or just download a zip with your App and install the additional data to the SD card that way.
You will need the WRITE_EXTERNAL_STORAGE permission like moritz suggests if you are writing to the SD card in any way.