Skip to content

cozynergy/cordova-ourcodeworld-filebrowser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cordova-ourcodeworld-filebrowser Plugin

A cordova implementation of NoNonsense-FilePicker for Android.

This plugin allow you to select folder and files, and at the same time create folders and create files (not a file is created actually, but it will return the filepath and name of the "choosen path").

Installation

Note : Fixes for Cordovoa v9.0.0

Install the plugin

$ cordova plugin add https://github.com/ourcodeworld/cordova-ourcodeworld-filebrowser.git

After installing the plugin, remember that the targetSdkVersion of cordova needs to be less than 24 e.g in Cordova 9.0.1, you need to specify inside the config.xml file of your project:

<platform name="android">
    <preference name="android-minSdkVersion" value="19" />
    <preference name="android-targetSdkVersion" value="23" />
</platform>

Usage

A global object OurCodeWorld.Filebrowser will be available in your window. This object offers a file picker, folder picker, mixed folder and file picker and the file creation dialog.

// Single file selector
window.OurCodeWorld.Filebrowser.filePicker.single({
    success: function(data){
        if(!data.length){
            // No file selected
            return;
        }

        // Array with filepaths
        // ["file:///storage/emulated/0/360/security/file.txt", "file:///storage/emulated/0/360/security/another-file.txt"]
    },
    error: function(err){
        console.log(err);
    }
});

// Single folder selector
window.OurCodeWorld.Filebrowser.folderPicker.single({
    success: function(data){
        if(!data.length){
            // No folders selected
            return;
        }

        // Array with paths
        // ["file:///storage/emulated/0/360/security", "file:///storage/emulated/0/360/security"]
        console.log(data);
    },
    error: function(err){
        console.log(err);
    }
});

Check the documentation to see more methods of the plugin like the creation of file, mixed file and folder picker etc.

External links

Fixes

To fix app crashes while pick a file in android.

Before install this plugin

    cordova plugin add cordova-plugin-androidx
    cordova plugin add cordova-plugin-androidx-adapter

After install this plugin

Include a provider element inside android platform AndroidManifest.xml

    <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/mnk_file_path" />
    </provider>

Create mnk_file_path named xml file under style folder inside android platform. and add following xml snippet.

    <?xml version="1.0" encoding="utf-8"?>
    <paths xmlns:android="http://schemas.android.com/apk/res/android">
        <root-path
            name="root"
            path="." />
    </paths>

-To fix issue as window.resolveLocalFileSystemURI is not a function. add cordova-plugin-file plugin

    cordova plugin add cordova-plugin-file

About

A native Android filebrowser (select and create files and folders) for Cordova

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 67.5%
  • JavaScript 32.5%