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

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

问题描述

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

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.

以下是 Apple 的教程:https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/RegisteringtheFileTypesYourAppSupports.html

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

是否有支持 Android 和 iOS 并为该功能提供 JS API 的 Cordova 插件?提前致谢.

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

推荐答案

可以在 Cordova 中实现 FileType 关联.

You can achieve FileType association in Cordova.

它包括 2 个步骤.

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

1) register files in Android Manifest / iOS plist as

清单

<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>

列表

<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) 使用 Cordova 的文件打开器插件

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

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

参考:AndroidiOSphonegap 社区论坛主题

希望有帮助.

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

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