采用Android ACTION_SEND通过Messenger和Facebook发送图像 [英] Using Android ACTION_SEND to send image via Messenger and Facebook

查看:361
本文介绍了采用Android ACTION_SEND通过Messenger和Facebook发送图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序我希望能够使用ACTION_SEND意图通过电子邮件或者,Facebook或使者(MMS)发送救了我的本地SD卡上的图片。随着code我有我可以成功地通过电子邮件发送照片作为附件,但是当我选择Facebook的我得到的错误,而加载照片时出错,当我尝试选择信使它说,对不起,你不能将此图片添加到您的留言。

In my app i want to be able to use the ACTION_SEND intent to send a picture saved on my local SD card by either Email, Facebook, or the Messenger(MMS). With the code I have I can sucessfully email the picture as an attachment but when I select Facebook i get the error, "An error occured while loading the photo" and when i try selecting the Messenger it says, "Sorry, You cannot add this picture to your message".

下面是我的code:

File pic =  new File(Environment.getExternalStorageDirectory()+ File.separator + "images" + File.separator + "picture.jpg");
                Uri pngUri = Uri.fromFile(pic);
                Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);  
                picMessageIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                picMessageIntent.setType("image/jpeg");  
                picMessageIntent.putExtra(Intent.EXTRA_STREAM, pngUri);
                startActivity(Intent.createChooser(picMessageIntent, "Send your picture using:"));

有没有人有任何想法,我需要改变,以使与Messenger和Facebook上分享这个code的工作?

Does anyone have any idea what i need to change to make this code work with the Messenger and Facebook?

推荐答案

要通过彩信发送图像,你必须得到媒体提供商的URI,URI从文件路径不工作(我遇到过这个问题)。对于Facebook,我不知道如何将用户ACTION_SEND送形象,因为我用的Facebook SDK发布状态和发送照片(这是一个更好的办法,因为你并不需要依靠其以前的Facebook手机安装)。

To send image with MMS, you must get the URI of media provider, URI from file path doesn't work (I met this problem before). For Facebook, I've no idea how to user ACTION_SEND to send image, since I used Facebook SDK to post status and send photo (and that is a much better way since you don't need to rely on phones which have facebook installed before).

protected void sendMMS(final String body, final String imagePath) {
    MediaScannerConnectionClient mediaScannerClient = new MediaScannerConnectionClient() {
        private MediaScannerConnection msc = null;
        {
            msc = new MediaScannerConnection(getApplicationContext(), this);
            msc.connect();
        }

        public void onMediaScannerConnected() {
            msc.scanFile(imagePath, null);
        }

        public void onScanCompleted(String path, Uri uri) {
            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.putExtra("sms_body", body);
            sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
            sendIntent.setType("image/png");
            startActivity(sendIntent);

            msc.disconnect();
        }
    };
}

这篇关于采用Android ACTION_SEND通过Messenger和Facebook发送图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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