如何实现一个Android应用程序的分享功能? [英] How to implement the SHARE function of a Android app?

查看:234
本文介绍了如何实现一个Android应用程序的分享功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我们可以看到,一些点击分享按钮,可共享的方式显示一个列表之后。这名单似乎动态生成的,而不是硬codeD。

Sometimes we can see that after clicking some "share" button, a list of sharable ways displays. And that list seems generated dynamically and not hard-coded.

例如,我已经安装在我的手机SpringPad,以及一些应用程序共享功能是能够通过共享的SpringPad内容,但它怎么会知道我有SpringPad?

For example, I have SpringPad installed on my phone, and some apps' sharing function is able to share the content via SpringPad, but how could it know that I have SpringPad?

如何实现这样的功能?谢谢你。

How to implement such a function? Thanks.

推荐答案

下面是我的Andr​​oid应用程序BBC新闻,这是否实际code。这股的URL页面。如果用户安装了Facebook和Twitter的应用程序,他们将提供机会分享这些服务,以及电子邮件等。

Here is the actual code from my Android app BBC News that does this. It shares the URL to the page. If the user has Facebook or Twitter apps installed they will be offered the opportunity to share to those services, as well as email etc.

        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, pageUrl);

        try {
          startActivity(Intent.createChooser(intent, "Select an action"));
        } catch (android.content.ActivityNotFoundException ex) {
          // (handle error)
        }

这篇关于如何实现一个Android应用程序的分享功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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