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

问题描述

我正在Facebook上使用ACTION_SEND分享图像,但是它不工作.code在这里

  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,
共享使用));
} catch(Exception e){
Toast.makeText(getBaseContext(),e.​​getMessage(),
Toast.LENGTH_SHORT).show();
}

但它会显示错误无法上传



我正在使用此链接()

解决方案

希望这将有助于您解决问题。

  @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,分享使用));
} 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);
}
返回类型;
}

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



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"

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

解决方案

Try this way,hope this will help you to solve your problem.

@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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 12:43