Android:使用意图共享纯文本(到所有消息传递应用程序) [英] Android: Share plain text using intent (to all messaging apps)

查看:31
本文介绍了Android:使用意图共享纯文本(到所有消息传递应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Intent 共享一些文本:

I'm trying to share some text using an intent:

Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");  
i.putExtra(android.content.Intent.EXTRA_TEXT, "TEXT");

并使用选择器进行变形:

and warping with chooser:

startActivity(Intent.createChooser(sms, getResources().getString(R.string.share_using)));

它有效!但仅适用于电子邮件应用程序.
我需要的是所有消息传递应用程序的总体意图:电子邮件、短信、IM(Whatsapp、Viber、Gmail、SMS...)尝试使用 android.content.Intent.ACTION_VIEW并尝试使用 i.setType("vnd.android-dir/mms-sms"); 没有任何帮助...

it works! but only for email app.
what I need is a general intent for all messaging app: emails, sms, IM (Whatsapp, Viber, Gmail, SMS...) tried using android.content.Intent.ACTION_VIEW and tried using i.setType("vnd.android-dir/mms-sms"); nothing helped...

("vnd.android-dir/mms-sms" 仅使用短信共享!)

("vnd.android-dir/mms-sms" shared using sms only!)

推荐答案

使用代码为:

    /*Create an ACTION_SEND Intent*/
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    /*This will be the actual content you wish you share.*/
    String shareBody = "Here is the share content body";
    /*The type of the content is text, obviously.*/
    intent.setType("text/plain");
    /*Applying information Subject and Body.*/
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.share_subject));
    intent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
    /*Fire!*/
    startActivity(Intent.createChooser(intent, getString(R.string.share_using)));

这篇关于Android:使用意图共享纯文本(到所有消息传递应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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