Cordova 从其他应用程序接收共享数据

2024-01-26

首先,请不要将此问题标记为重复。所有其他问题都是老问题,我已经尝试了其中大多数的解决方案,但没有一个有效。

我正在开发一个 Android 应用程序,并且添加了我的应用程序来共享 Android 菜单。我想添加功能,这样如果用户在共享列表上单击我的应用程序,例如在 Chrome 浏览器或 Google Drive 应用程序中,我的应用程序将从该应用程序接收数据,例如在 Chrome 中,它是 URL。

我尝试使用不同的插件并阅读了许多有关如何在我的应用程序中使用意图的帖子。不幸的是,它们都不起作用。 我试过了:

  • 通过 webintents 从另一个应用程序发送 url 到 ionic android 应用程序 https://stackoverflow.com/questions/32856046/sending-url-to-ionic-android-app-via-webintents-from-another-app/34444688#34444688- 这个看起来很有前途
  • https://www.npmjs.com/package/phonegap-webintent https://www.npmjs.com/package/phonegap-webintent
  • https://github.com/napolitano/cordova-plugin-intent https://github.com/napolitano/cordova-plugin-intent- 这个看起来也很有前途
  • https://github.com/okwei2000/webintent https://github.com/okwei2000/webintent
  • https://github.com/stample/cordova-sharingreceptor https://github.com/stample/cordova-sharingreceptor

有人让这个工作了吗? 我的AndroidManifest.xml如下 - 关于意图的部分:

        <intent-filter android:label="@string/launcher_name">
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <action android:name="android.intent.action.SEND_MULTIPLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*" />
        </intent-filter>

在我的 config.xml 中,我有:

<preference name="AndroidLaunchMode" value="singleTask" />

而且我没有得到我期望的数据。

当我使用时https://github.com/napolitano/cordova-plugin-intent https://github.com/napolitano/cordova-plugin-intent插件 我明白了意图,但缺少 ClipItems 元素,并且该插件毫无用处。

我究竟做错了什么?

任何帮助表示赞赏。


最后我做到了。 我用了https://github.com/napolitano/cordova-plugin-intent https://github.com/napolitano/cordova-plugin-intent版本 0.1.3 和

window.plugins.intent.setNewIntentHandler(function (intent) {
    // To get browser URL I had to use
    var subject = intent.extras['android.intent.extra.SUBJECT'];
    var url = intent.extras['android.intent.extra.TEXT'];
    // For Chrome, Opera and FireFox it works. For build in Android browser TEXT holds page title and URL joined with +
});

虽然0.1.3版有

window.plugins.intent.getRealPathFromContentUrl(contentUrl, function (realPath) {}, function () {});

可用我无法使用它,因为这没有给我我想要的数据。 contentUrl 对于不同的浏览器是不同的,例如对于 Chrome,它是 uri;对于 Android 浏览器中的构建,它是文本。

我使用 CLI 安装了 0.1.3 版

phonegap plugin add https://github.com/napolitano/cordova-plugin-intent.git#61a47ae8c28a62004eeff4ed96a6f3c64c271a16

我无法使用 config.xml 中的标签添加它

我希望这会帮助其他人。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Cordova 从其他应用程序接收共享数据 的相关文章

随机推荐