如何在谷歌加Android中的http url分享图像?

时间:2015-03-04 09:17:07

标签: android google-plus

我想与google plus个人资料分享在线图片。在我的应用中,我现在获取图片网址,我想在google plus个人资料上分享。

1 个答案:

答案 0 :(得分:3)

   File tmpFile = new File("/path/to/image");
 final String photoUri = MediaStore.Images.Media.insertImage(
         getContentResolver(), tmpFile.getAbsolutePath(), null, null);

 Intent shareIntent = ShareCompat.IntentBuilder.from(this)
         .setText("Hello from Google+!")
         .setType("image/jpeg")
         .setStream(Uri.parse(photoUri))
         .getIntent()
         .setPackage("com.google.android.apps.plus");

以下代码从网址下载图片

 try {
        URL url = new URL(link);
        HttpURLConnection connection = (HttpURLConnection) url
                .openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input);

        return myBitmap;

    } catch (IOException e) {
        e.printStackTrace();
        Log.e("getBmpFromUrl error: ", e.getMessage().toString());
        return null;
    }