无法将我的应用程序中的图像作为隐式意图发送到外部应用程序

时间:2017-03-24 17:05:37

标签: java android android-intent

我是android的新手我已经从stackoverflow和其他资源上阅读了这个问题,但我尽力获得结果 在发送时我选择gmail发送我的图像,但其显示空文件不能附加 我尝试在我的包中使用不同的图像,但我得到相同的响应 这是我试过的代码

    Intent intent;     
   Uri imageUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
                        "://" + getResources().getResourcePackageName(R.drawable.cursor)
                        + '/' + getResources().getResourceTypeName(R.drawable.cursor) + '/' +
                        getResources().getResourceEntryName(R.drawable.cursor) );
                intent=new Intent(Intent.ACTION_SEND);
                intent.setType("image/jpeg");
                intent.putExtra(Intent.EXTRA_STREAM, imageUri);
                chooser=Intent.createChooser(intent, "Select app to send");
                startActivity(chooser);

1 个答案:

答案 0 :(得分:0)

希望这会有所帮助:

BitmapFactory.Options options = new BitmapFactory.Options(); 
options.outMimeType = "image/jpeg";

Bitmap bitmap= BitmapFactory.decodeResource(getResources(),
        R.mipmap.ic_launcher, options);

String path = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, "Image Description", null);
Uri uri = Uri.parse(path);

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/jpeg");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share Image"));