Flutter create file in download folder - android

In my app I need to download some bills.
On IOS my users can easily find them when app is closed because it is stored in a dedicated folder easily findable. I achieve that with getApplicationDocumentsDirectory() from path_provider and the following option in plist :
<key>UISupportsDocumentBrowser</key>
<true/>
In android, downloaded files aren't put inside the download folder but inside the app data folder which is hard for a simple user to understand how to go in. What can I do to put bills (pdf) inside the Android Download folder ?
I use for the moment the method getExternalStorageDirectory() from path_provider for Android.

Based on #blackapps responses, I used the following hard coded path in Android and fallback to getExternalStorageDirectory() if folder didn't exist.
final Directory directory = Directory('/storage/emulated/0/Download');
if (!await directory.exists()) directory = await getExternalStorageDirectory();

Related

Do all Android devices have a common downloads directory path?

I am developing a Flutter app. I am trying to save a pdf file to the device's downloads directory.
The path looks like this: /storage/emulated/0/Download
Can I assume that all Android devices store downloads in this location, or are there exceptions?
It is usually a good idea to not just hardcode a path. the path_provider package will help you here. https://pub.dev/packages/path_provider
It lets you get the directory you are looking for like this:
import 'package:path_provider/path_provider.dart' as pathProvider;
String dir = (await pathProvider.getDownloadsDirectory()).path;
It of course also works for iOS and lets you get the path for many different directories.

Aead write file in specific folder flutter

Anyone know how to access a particular folder in phone storage using flutter? i want to read a abc.MP4 file and save it to another location inside phone storage ?
You can check Reading-Writing-Files documentation, there explains to you how to do it.
And I guess you want to copy the File to another path so you can take a look on File.copy documentation
Future<File> copy (
String newPath
)

How to access file in android internal storage for unity app?

I am using EasyMovieTexture plugin and I want to get access to android folder where all the videos are saved. First I tried to access the streaming asset folder but it is not accessible in the app (Copying files into asset folder in android) so I have created folder in which all the videos are and I want to access that particular folder to play the videos individually. Here is a sample code which loads the video from url but I want it to access it from storage -
void OnGUI() {
if( GUI.Button(new Rect(50,50,100,100),"Load"))
{
scrMedia.Load("Url of video");
m_bFinish = false;
}
how to access the videos in interval storage to play them. Thanks in advance.
You can use Application.persistentDataPath to access internal storage.
https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
You can see which directory it is using
Debug.log(Application.persistentDataPath)
Any files in a StreamingAssets folder will be included in your build, accessible at the path specified by Application.streamingAssetsPath.
However, the manual mentions an important caveat for Android:
On Android, the files are contained within a compressed .jar file (which is essentially the same format as standard zip-compressed files). This means that if you do not use Unity’s WWW class to retrieve the file, you need to use additional software to see inside the .jar archive and obtain the file.
If your video plugin can access the file within an APK, then you'll just need to specify the correct path.
If your video plugin expects a conventional file, then you will need to create one. Unity's WWW class can read the compressed file into memory, which you could then write to some other location (such as Application.temporaryCachePath) with System.File.WriteAllBytes.

List the files that are stored in the download folder on an Android device

How do you retrieve the list of files that are stored in the download folder on android phone.
I have an cordova based app that contains a button. When it is press, I would like to show the user a list a files in their download folder and let them select one..
I have the "cordova-plugin-file" installed and I tried accessing the information from the following folders"
var localURLs = [
cordova.file.dataDirectory,
cordova.file.documentsDirectory,
cordova.file.externalApplicationStorageDirectory,
cordova.file.externalCacheDirectory,
cordova.file.externalRootDirectory,
cordova.file.externalDataDirectory,
cordova.file.sharedDirectory,
cordova.file.syncedDataDirectory
];
and the code from How to get documents in an android directory that PhoneGap will see
However, none of the folders return the files stored in the download folder on the device.
Is there another method to access this information..
Thanks

access files from assets/www directory

let's say I've got a file called foo.html sitting (quite comfortable) in my assets/www directory (next to my index.html).
I'd like to copy that file to another location on the device. My first approach window.resolveLocalFileSystemURI("foo.html", cool(), notCool());is not working. Also with a prefix like www/ it won't.
It would be interesting to know if it is actually possible at all to access files via Phonegap. I'm not convinced and therefore would like to see a code snippet how to obtain a FileEntry for files in the assets directory - if possible.
edit:
Ok now we've got a call like this
window.resolveLocalFileSystemURI("file:///android_asset",
function(entry){
console.log(entry.fullPath);},
function(evt){
console.log(evt.code);}
);
but we've get an error with code: undefined (Phonegap v1.2) and code: 1 with v1.0 (code 1 = file not found?!)
You can't do what you want to do. The files in the assets directory are not technically on the file system so they are not accessible via the File API. This means calling window.resolveLocalFileSystemURI() will not return you a FileEntry.
The best you can hope for is to access those files via XHR. If they are text based you can always take the result of the XHR and write it to the file system using the FileWriter. I wrote a blog post that shows how to get a file from the assets directory using XHR.
http://simonmacdonald.blogspot.com/2011/12/on-fourth-day-of-phonegapping-creating.html
You should be able to access the file this way:
window.resolveLocalFileSystemURI("file:///android_asset/www/foo.html", onResolveSuccess, onFail);
You can then use the File API - FileEntry.copyTo or FileEntry.moveTo to actually do the action. Note - you cannot actually write into the assset/www folder, only to an SD card.
Hope this helps
Leon - "you cannot actually write into the assset/www folder, only to an SD card" The first part is true, you can not write to the asset/www path. But, if the app is installed on the device, you can create and write to a file and it gets created at android's root. If the app is installed on an SD card, that file gets created at the SD card's root. Files thusly created are NOT deleted or altered when clearing user data for the app and are NOT deleted when the app is deleted.

Categories

Resources