将内容分享到 phonegap 应用程序 [英] Share something to a phonegap app

查看:23
本文介绍了将内容分享到 phonegap 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以注册一个phonegap应用程序,让它出现在应用程序的菜单中进行共享吗?

Is there any way to register a phonegap app to appear in the menu of applications to share?

推荐答案

要出现在此列表中,您必须修改 AndroidManifest.xml 文件并在您的活动下添加以下几行:

To appear in this list you have to modify the AndroidManifest.xml file and add the following lines under your activity :

<intent-filter> 
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
</intent-filter>

这将使您的应用出现在列表中.现在我想你可能还想知道如何在你的代码中处理这个问题.当另一个应用程序要与您共享一些文本时,它将以 Android意图"启动您的应用程序.为了能够使用 Intent,您需要一个 PhoneGap 插件.我认为 WebIntent 可能适合你.这将是代码:

This will make your app appear in the list. Now I think you may probably also want to know how to handle this in your code. When another application is going to share some text with you, it's going to start your application with an Android "Intent". To be able to use Intents, you need a PhoneGap plugin. I think WebIntent might suit you. This would be the code :

// deviceready is PhoneGap's init event
document.addEventListener('deviceready', function () {
  window.plugins.webintent.getExtra(WebIntent.EXTRA\_TEXT, function (url) {
    // url is the value of EXTRA_TEXT 
  }, function() {
    // There was no extra supplied.
  });
});

有关 WebIntent 的更多信息:http://smus.com/android-phonegap-plugins/

More info on WebIntent here : http://smus.com/android-phonegap-plugins/

注意:虽然我认为您无法使用 PhoneGap Build 执行此操作...您只能使用受支持的插件,并且不能对 AndroidManifest.xml 文件进行太多更改.您可能必须走 Cordova 路线并在您的机器上构建所有内容.

Note : I don't think you'll be able to do this with PhoneGap Build though ... you can only use supported plugins, and can't change the AndroidManifest.xml file that much. You'll probably have to go the Cordova route and build everything on your machine.

有几个人询问如何在 iOS 上执行此操作.有两个步骤可以做到这一点:

Edit : there are a few people asking how to do this on iOS. There are two steps to do this :

  1. 通过在 info.plist 中添加相关信息,将您的应用与正确的文件类型关联.这个 SO 答案解释了如何做到这一点:How do I将文件类型与 iPhone 应用程序相关联?.这将使您的应用出现在列表中,但您的应用还不会接收数据.
  2. 您的应用程序现在将使用新参数启动.您现在必须能够读取这些参数.在 SO 上检查这个问题/答案,它确实如此:How将参数传递给基于 Phonegap 的应用
  1. Associate your app with the right file type associations by adding the relevant information in your info.plist. This SO answer explains how to do it : How do I associate file types with an iPhone application?. This will make your app appear in the list but your app won't receive the data yet.
  2. Your application will now be launched with new parameters. You now have to be able to read these parameters. Check this question/answer on SO, it does exactly that : How to pass arguments to app built on Phonegap

这篇关于将内容分享到 phonegap 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆