Cordova将文件类型注册为“打开方式”列表

问题描述 投票:9回答:2

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

这是Apple的一个教程:qazxsw poi

有没有支持Android和iOS的Cordova插件,并为该功能提供了JS API?提前致谢。

android ios cordova mobile ionic-framework
2个回答
6
投票

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

它包括两个步骤。

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

表现

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

plist中

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

2)使用<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>

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

参考:File Opener Plugin for CordovaAndroidiOS

希望能帮助到你。


1
投票

检查这个phonegap community forum thread。关于Let'sRefactor,除了fileopener之外它是正确的,在意图中你应该确定当用户用你的app打开文件时要调用的函数(当然是本机)。这一切都在上面的链接中解释。

© www.soinside.com 2019 - 2024. All rights reserved.