android

时间:2016-12-12 11:19:18

标签: android image uri

我已将Image作为字符串URL

但我必须像内容uri格式一样传递此图像 这样的事情: - content:// media / external / images / media / 35001
怎么做??

我需要图片URI而不是网址然后只有我可以将图片分享到社交媒体,如twitterfacebook等。但我将图像作为字符串url.So我可以&#39 ; t分享图像。
下面给出的是代码: -

 ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
        // continue with your code
        path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "Title", null);
        image = Uri.parse(path);

        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("text/plain");
        share.putExtra(android.content.Intent.EXTRA_TEXT, "I posted this text  " );
        share.putExtra(Intent.EXTRA_STREAM, image);
        share.setType("image/jpeg");
        startActivity(Intent.createChooser(share, "Share"));

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码将URL转换为URI: -

 String your_url = "http://example.com.au/Images/8e6c8e7b-7b97-494d-ac8b-27064841dfd3.jpg";
 URI uri = new URI(your_url.toString());