cordova-file-association

File association plugin for cordova. Main purpose is to make possible to associate cordova app with file types well known or custom made. Currently it is for Android only.

Usage no npm install needed!

<script type="module">
  import cordovaFileAssociation from 'https://cdn.skypack.dev/cordova-file-association';
</script>

README

cordova-fileAssociation

File association plugin for cordova. Main purpose is to make possible to associate cordova app with file types well known or custom made. Currently it is for Android only.

How to use it 1.Clone from git git clone 2.Configure your AndroidManifest.xml activity for example for json file:

....

......
        <!--
            opening by email application
        -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="application/json" />
        </intent-filter>

        <!--
            opening from remote ex. with http (ex. browser)
        -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="http" />
            <data android:host="*" />
            <data android:pathPattern=".*\\.json" />
        </intent-filter>
        .....
    </activity>

3.Add plugin to project by: cordova plugin add /FileAssociation

4.Register listeners in your cordova app to be sure that plugin is available to use:

var fileAssociation = function () { if (!window.plugins) { console.log("plugins not defined"); return; }

            window.plugins.fileAssociation.getAssociatedData(null,
                function (success) {
                    try {
                        if (success != null) {
                            //handle your data here maybe ex. by promise 
                            activityPromise.resolve(decoded);
                        }
                    } catch (e) {
                        activityPromise.reject(e);
                    }
                }, function (error) {
                    activityPromise.reject(error);
                });
        };

//added to be sure that plgin is available document.addEventListener("resume", function () { loadFromActivity(); }, false);

        document.addEventListener("deviceready", function () {
            loadFromActivity();
        }, false);

5.Use well