在android中分享图像的意图

时间:2016-07-08 17:40:56

标签: android share-intent

这是我的代码:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.sharebutton:
            shareImage();
            break;

        default:
            return super.onOptionsItemSelected(item);
    }
    return true;
}

private void shareImage() {
    Intent share = new Intent(Intent.ACTION_SEND);

     share.setType("image/*");
    String imagePath = Environment.getExternalStorageDirectory()
            + "/myImage.png";

    File imageFileToShare = new File(imagePath);

    Uri uri = Uri.fromFile(imageFileToShare);
    share.putExtra(Intent.EXTRA_STREAM, uri);
    Bitmap bmp = BitmapFactory.decodeFile(imagePath);

    startActivity(Intent.createChooser(share, "Share"));
}

我正在尝试分享我的图片,但它并没有分享。我没有错。谁能说出问题是什么?

1 个答案:

答案 0 :(得分:0)

String pathURL = "File Real Path"
Uri bmpUri = Uri.fromFile(new File(pathURL));
Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("image/*");
    shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
    startActivity(Intent.createChooser(shareIntent, "Share Image"));