在 Android 中共享图像的意图



这是我的代码:

@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"));
}

我正在尝试分享我的图像,但它没有共享。我没有收到任何错误。谁能说出问题出在哪里?

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"));

相关内容

  • 没有找到相关文章

最新更新