Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova register file types to 'open with' list

I'd like to register my Ionic app (through Cordova) to open certain file types. Just like Dropbox does. When a user has a file on another application (like email), and he clicks 'open with', there's a list which contains the Dropbox app.

Heres a tutorial from Apple: https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/RegisteringtheFileTypesYourAppSupports.html

Is there any Cordova plugin that support both Android and iOS and gives a JS API to that feature? Thanks in advance.

like image 792
Daniel Golub Avatar asked May 31 '15 16:05

Daniel Golub


2 Answers

check this link. Regarding Let'sRefactor its is correct except for fileopener , in the intent you should identify what function to call ( in native of-course ) when a user open file with your app. It is all explained in the link above.

like image 93
ram mere Avatar answered Sep 21 '22 05:09

ram mere


You can achieve FileType association in Cordova.

It includes 2 steps.

1) register files in Android Manifest / iOS plist as

Manifest

<intent-filter
    android:icon='@drawable/ic_launcher'
        android:label='AndroidMHT File'
    android:priority='1'>
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.intent.action.EDIT" /> 
    <action android:name="android.intent.action.PICK" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:mimeType="*/*" />
    <data android:pathPattern="*.mht" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http" android:host="*" android:pathPattern=".*\\.mht" />
    <data android:scheme="https" android:host="*" android:pathPattern=".*\\.mht" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:mimeType="message/rfc822" android:scheme="http" />
    <data android:mimeType="multipart/related" android:scheme="http" />
    <data android:mimeType="message/rfc822" android:scheme="https" />
    <data android:mimeType="multipart/related" android:scheme="https" />
</intent-filter>

plist

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>Document-molecules-320.png</string>
            <string>Document-molecules-64.png</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Molecules Structure File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.sunsetlakesoftware.molecules.pdb</string>
            <string>org.gnu.gnu-zip-archive</string>
        </array>
    </dict>
</array>

2) Use the File Opener Plugin for Cordova

You may need to pass necessary flags to open those files.

Reference: Android, iOS and a phonegap community forum thread

Hope it helps.

like image 35
Let'sRefactor Avatar answered Sep 22 '22 05:09

Let'sRefactor