通过Whatsapp或Facebook分享图片和文字 [英] Share image and text through Whatsapp or Facebook

查看:776
本文介绍了通过Whatsapp或Facebook分享图片和文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中有一个共享按钮,我想同时分享一个图像和一个文本。在GMail中,它可以正常工作,但在WhatsApp中,只有图像被发送,并且在Facebook中应用程序崩溃。



我用于共享的代码是:

  Intent shareIntent = new Intent(Intent.ACTION_SEND); 
shareIntent.setType(image / *);
shareIntent.putExtra(Intent.EXTRA_TEXT,Message);

Uri uri = Uri.parse(android.resource://+ getPackageName()+/ drawable / ford_focus_2014);
try {
InputStream stream = getContentResolver()。openInputStream(uri);
} catch(FileNotFoundException e){
// TODO自动生成的catch块
e.printStackTrace();
}

shareIntent.putExtra(Intent.EXTRA_STREAM,uri);

如果我使用shareIntent.setType(* / *)Facebook和WhatsApp崩溃。 / p>

有没有办法呢?也许同时发送两条消息(WhatsApp)。



提前感谢

解决方案

这是不可能的,因为WhatsApp不支持其中包含图片和文字的邮件。消息可以由单个图像,文本序列,音频文件,联系人或视频组成。



您可以使用

分享您的文字。  Intent whatsappIntent = new Intent(Intent.ACTION_SEND); 
whatsappIntent.setType(text / plain);
whatsappIntent.setPackage(com.whatsapp);
whatsappIntent.putExtra(Intent.EXTRA_TEXT,您要共享的文本);
try {
activity.startActivity(whatsappIntent);
} catch(android.content.ActivityNotFoundException ex){
ToastHelper.MakeShortText(Whatsapp尚未安装);
}


I have in my app a share button and i want to share an image and a text at the same time. In GMail it works fine but in WhatsApp, only the image is sent and in Facebook the app crashes.

The code i use to share is this:

Intent shareIntent = new Intent(Intent.ACTION_SEND);  
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Message");         

Uri uri = Uri.parse("android.resource://" + getPackageName() + "/drawable/ford_focus_2014");
     try {
        InputStream stream = getContentResolver().openInputStream(uri);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

If I use "shareIntent.setType("*/ *")" Facebook and WhatsApp crashes.

Is there some way to do this? Maybe sent two messages by separate at the same time (WhatsApp).

Thanks in advance.

解决方案

This is not possible, as WhatsApp does not support messages with both pictures and text in them. A message may consist of a single image, text sequence, audio file, contact or video. You cannot have a combination of any of those.

Rather u can share your text using

    Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
    whatsappIntent.setType("text/plain");
    whatsappIntent.setPackage("com.whatsapp");
    whatsappIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
    try {
        activity.startActivity(whatsappIntent);
    } catch (android.content.ActivityNotFoundException ex) {
        ToastHelper.MakeShortText("Whatsapp have not been installed.");
    }

这篇关于通过Whatsapp或Facebook分享图片和文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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