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

标签 android cordova android-intent

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

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

我尝试过使用不同的插件并阅读了很多关于如何在我的应用中使用 Intent 的帖子。不幸的是,它们都不起作用。 我试过:

有人成功了吗? 我的 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/

相关文章:

Android startActivityForResult 不返回日历数据

安卓客户端服务器应用

android - Firebase 实时数据库 : Using Firebase Realtime Database in always running service in Android

android - Android 中的 Google Plus 封面照片

android - 您如何处理 Android 身份验证后的重定向?

ios - Ionic 2 - 当应用程序在 IOS 上处于前台时显示通知

cordova - 有没有办法混淆整个 Cordova/Phonegap 项目?

xcode - 获取生产 APNS token

android - 无法在 Eclipse IDE 上获取项目的系统库

java - 将字符串数组传递给另一个 Activity 以与 ion 一起使用