Cordova注册文件类型为“打开方式”列表 [英] Cordova register file types to 'open with' list

查看:209
本文介绍了Cordova注册文件类型为“打开方式”列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想注册我的Ionic应用程序(通过Cordova)打开某些文件类型。就像Dropbox一样。当用户在另一个应用程序(如电子邮件)上有一个文件,并点击打开方式时,会有一个包含Dropbox应用程序的列表。



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



是否有支持Android和iOS的Cordova插件,并且一个JS API的功能?提前感谢。

解决方案

您可以在Cordova中实现FileType关联。



<

1)在Android Manifest / iOS plist中注册文件为



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 =httpandroid:host =*android:pathPattern =。* \\.mht/>
< data android:scheme =httpsandroid: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 / rfc822android:scheme =http/>
< data android:mimeType =multipart / relatedandroid:scheme =http/>
< data android:mimeType =message / rfc822android:scheme =https/>
< data android:mimeType =multipart / relatedandroid: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>分子结构文件< / string>
< key> CFBundleTypeRole< / key>
< string>查看器< / 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)使用 Cordova的文件打开程序插件



您可能需要传递必要的标志才能打开这些文件。 p>

参考: Android iOS phonegap社区论坛主题



希望它有帮助。


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.

解决方案

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.

这篇关于Cordova注册文件类型为“打开方式”列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆