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

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

本文介绍了Cordova从其他应用程序接收共享数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,请不要将此问题重复.所有其他问题都很老,我尝试了其中大多数的解决方案,但都无济于事.

At first please do not mar this question as duplicate. All other questions are old and I've tried solutions from most of them and none of them work.

我正在开发一个Android应用程序,并且添加了我的应用程序以共享Android菜单.我想添加功能,以便如果用户在共享列表上单击我的应用,例如在Chrome浏览器或Google云端硬盘应用中,我的应用会从该应用接收数据,例如在Chrome中,它应该是URL.

I'm working on an Android app and I'd added my app to share Android menu. I'd like to add functionality so if user clicks my app on the share list e.g. in Chrome browser or Google Drive app, my app will receive the data from that app e.g. from Chrome it wold be URL.

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

I've tried to use different plugins and read many posts about how to use intent in my app. Unfortunately none of them work.I've tried:

  • Sending url to ionic android app via webintents from another app - this one looked very promising
  • https://www.npmjs.com/package/phonegap-webintent
  • https://github.com/napolitano/cordova-plugin-intent - this one looked promising as well
  • https://github.com/okwei2000/webintent
  • https://github.com/stample/cordova-sharingreceptor

有人进行过这项工作吗?我的AndroidManifest.xml如下-有关意图的部分:

Did anyone got this working?My AndroidManifest.xml is as follows - the part about 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中,我有:

In my config.xml I have:

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

我没有得到期望的数据.

And I'm not getting data I'm expecting.

当我使用> https://github.com/napolitano/cordova-plugin-意图插件我已经有了意图,但是缺少clipItems元素,该插件没用.

When I'm using https://github.com/napolitano/cordova-plugin-intent plugin I'm getting the intent but clipItems element is missing and the plugin is useless.

我在做什么错了?

任何帮助表示赞赏.

推荐答案

最后,我已经完成了.我使用了 https://github.com/napolitano/cordova-plugin-intent ver 0.1.3和

Finally I've done it.I used https://github.com/napolitano/cordova-plugin-intent ver 0.1.3 and

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浏览器中构建的,它是文本.

available I couldn't use it because this didn't give me the data I wanted. contentUrl is different for differen browsers e.g. for Chrome it is uri and for build in Android browser it's text.

我使用CLI安装了0.1.3版

I installed ver 0.1.3 using CLI

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

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

I couldn't add it using tag in config.xml

我希望这会对其他人有所帮助.

I hope this will help others.

这篇关于Cordova从其他应用程序接收共享数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 10:13