Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android共享意图不加载图像_Android_Android Intent - Fatal编程技术网

Android共享意图不加载图像

Android共享意图不加载图像,android,android-intent,Android,Android Intent,当我尝试使用intent在facebook上共享图像时,收到消息“抱歉,我们无法加载您的照片” 我正在使用以下代码 Uri imageUri = Uri.parse("android.resource://"+getPackageName()+"/drawable/"+filename); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("image/jpg");

当我尝试使用intent在facebook上共享图像时,收到消息“抱歉,我们无法加载您的照片”

我正在使用以下代码

         Uri imageUri = Uri.parse("android.resource://"+getPackageName()+"/drawable/"+filename);
         Intent intent = new Intent(Intent.ACTION_SEND);
         intent.setType("image/jpg");
         intent.putExtra(Intent.EXTRA_STREAM, imageUri);             
         startActivity(Intent.createChooser(intent , "Share"));     
当我试图通过gmail发送邮件时,没有收到任何附件。 我可以知道原因吗?

某些应用程序(如Gmail、Facebook、Google Plus…)无法获取照片以附加,因为您的imageUri是私有的

public void shareImage()
{
Bitmap icon = mBitmap;
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
try {
    f.createNewFile();
    FileOutputStream fo = new FileOutputStream(f);
    fo.write(bytes.toByteArray());
} catch (IOException e) {                       
        e.printStackTrace();
}
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));
startActivity(Intent.createChooser(share, "Share Image"));


}
您应该将drawable保存到gallery或公用文件夹,然后获取newImageUri进行共享。
intent.putExtra(intent.EXTRA_流,newImageUri)

是的,我明白这一点,并以同样的方式做了。谢谢