分享图像不是通过ACTION.SEND工作 [英] Share image is not working via ACTION.SEND

查看:183
本文介绍了分享图像不是通过ACTION.SEND工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我共享图像在Facebook上使用ACTION_SEND,但它不工作。code在这里

I am sharing image on facebook using ACTION_SEND, but its not working .code is here

try {
                File myFile = new File("/mnt/sdcard/DCIM/100MEDIA/aa.jpg");
                MimeTypeMap mime = MimeTypeMap.getSingleton();
                String ext = myFile.getName().substring(
                        myFile.getName().lastIndexOf(".") + 1);
                String type = mime.getMimeTypeFromExtension(ext);
                Intent sharingIntent = new Intent(
                        "android.intent.action.SEND");
                sharingIntent.setType(type);
                sharingIntent.putExtra("android.intent.extra.STREAM",
                        Uri.fromFile(myFile));
                startActivity(Intent.createChooser(sharingIntent,
                        "Share using"));
            } catch (Exception e) {
                Toast.makeText(getBaseContext(), e.getMessage(),
                        Toast.LENGTH_SHORT).show();
            }

但它给错误无法上传

but it gives the error "Cannot upload"

我使用这个链接(<一href="http://stackoverflow.com/questions/11081231/share-image-via-android-app-using-action-send-not-working">Share通过使用ACTION_SEND不工作)Android应用程序图像

I am using this link ("Share Image via android app using ACTION_SEND not working")

推荐答案

试试这个办法,希望这将帮助你解决你的问题。

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);

   try {
       File myFile = new File(Environment.getExternalStorageDirectory()+"/100MEDIA/aa.jpg");
       Intent sharingIntent = new Intent("android.intent.action.SEND");
       sharingIntent.setType(getMimeType(myFile.getPath()));
       sharingIntent.putExtra("android.intent.extra.STREAM",Uri.fromFile(myFile));
       startActivity(Intent.createChooser(sharingIntent,"Share using"));
   } catch (Exception e) {
      Toast.makeText(getBaseContext(), e.getMessage(),Toast.LENGTH_SHORT).show();
   }
}

public String getMimeType(String filePath) {
   String type = null;
   String extension = getFileExtensionFromUrl(filePath);
   if (extension != null) {
       MimeTypeMap mime = MimeTypeMap.getSingleton();
       type = mime.getMimeTypeFromExtension(extension);
   }
   return type;
}

public String getFileExtensionFromUrl(String url) {
    int dotPos = url.lastIndexOf('.');
    if (0 <= dotPos) {
        return (url.substring(dotPos + 1)).toLowerCase();
    }
    return "";
}

这篇关于分享图像不是通过ACTION.SEND工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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