分享的东西到phonegap应用程序 [英] Share something to a phonegap app

查看:128
本文介绍了分享的东西到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>

这会让您的应用程式显示在清单中。现在我想你可能也想知道如何处理这个在你的代码。当另一个应用程序要与您共享一些文本时,它将使用AndroidIntent启动您的应用程序。为了能够使用Intents,你需要一个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构建虽然...你只能使用支持的插件,并且不能改变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回答解释了如何执行此操作:我如何将文件类型与iPhone应用程序关联?。这将使您的应用显示在列表中,但您的应用将无法接收数据。

  2. 您的应用现在将使用新参数启动。您现在必须能够读取这些参数。在SO上检查此问题/答案,它的确如此:如何将参数传递到基于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天全站免登陆