【问题标题】:Cordova receive shared data from other appCordova 从其他应用程序接收共享数据
【发布时间】:2017-04-26 12:25:00
【问题描述】:

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

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

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

有人搞定这个吗? 我的 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 插件时,我得到了意图,但缺少 clipItems 元素并且插件无用。

我做错了什么?

任何帮助表示赞赏。

【问题讨论】:

    标签: android cordova android-intent


    【解决方案1】:

    我终于做到了。 我使用了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 () {});
    

    available 我无法使用它,因为它没有给我想要的数据。 contentUrl 对于不同的浏览器是不同的,例如对于 Chrome,它是 uri,对于内置 Android 浏览器,它是文本。

    我使用 CLI 安装了 0.1.3 版

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

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

    我希望这对其他人有帮助。

    【讨论】:

    • 它在 ios 和 android 中都可以使用吗?我正在尝试在我的应用中实现相同的功能
    • 它适用于安卓系统。我没有在iOS上测试它。但是,如果您要在 iOS 上进行测试,请随时添加评论。
    • 当然。你需要什么?
    • 将我们的应用添加到共享菜单以及如何从那里处理操作?
    • 稍后我会更新我的答案。我需要去我的办公室。
    猜你喜欢
    • 1970-01-01
    • 2015-05-02
    • 1970-01-01
    • 2013-05-17
    • 2014-05-11
    • 2021-06-30
    • 2017-03-20
    • 1970-01-01
    • 2018-11-06
    相关资源
    最近更新 更多