首先请不要将此问题视为重复。所有其他问题都是老问题,我已经尝试了其中大多数的解决方案,但没有一个有效。
我正在开发一个 Android 应用程序,我添加了我的应用程序来共享 Android 菜单。我想添加功能,以便如果用户在共享列表中单击我的应用程序,例如在 Chrome 浏览器或 Google Drive 应用程序中,我的应用程序将从该应用程序接收数据,例如在 Chrome 中,它将是 URL。
我尝试过使用不同的插件并阅读了很多关于如何在我的应用中使用 Intent 的帖子。不幸的是,它们都不起作用。 我试过:
- Sending url to ionic android app via webintents from another app - 这个看起来很有前途
- https://www.npmjs.com/package/phonegap-webintent
- https://github.com/napolitano/cordova-plugin-intent - 这个看起来也很有前途
- https://github.com/okwei2000/webintent
- https://github.com/stample/cordova-sharingreceptor
有人成功了吗? 我的 AndroidManifest.xml 如下 - 关于 Intent 的部分:
<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 时插件我得到了 Intent ,但 clipItems 元素丢失,插件无用。
我做错了什么?
感谢任何帮助。
最佳答案
我终于做到了。 我用了https://github.com/napolitano/cordova-plugin-intent ver 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 +
});
虽然ver 0.1.3有
window.plugins.intent.getRealPathFromContentUrl(contentUrl, function (realPath) {}, function () {});
available 我不能使用它,因为它没有给我想要的数据。 contentUrl 对于不同的浏览器是不同的,例如对于 Chrome,它是 uri,对于在 Android 浏览器中构建,它是文本。
我使用 CLI 安装了 ver 0.1.3
phonegap plugin add https://github.com/napolitano/cordova-plugin-intent.git#61a47ae8c28a62004eeff4ed96a6f3c64c271a16
我无法在 config.xml 中使用标签添加它
我希望这对其他人有帮助。
关于android - Cordova 从其他应用程序接收共享数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41087273/