在 android 中使用 Fabric SDK 进行 Twitter 分享

Twitter sharing using Fabric SDK in android

我想使用我的应用程序在 Twitter 上分享图片和文字。我使用 Fabric SDK 并遵循其官方网站上的指南。问题是我的图像没有存储在 phone 存储中,它是 URL link。所以当我通过 URL 它不像 FB 共享那样显示。

下面我暂时发布了尝试过的代码。

private void shareViaTwitt() {
        final String myUrlStr = "http://i.stack.imgur.com/2FCsj.png";
        URL url;
        Uri uri = null;
        try {
            url = new URL(myUrlStr);
            uri = Uri.parse(url.toURI().toString());
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }

            TweetComposer.Builder builder = new TweetComposer.Builder(getContext())
                    .text("Hi this is Sample twitter sharing")
                    .image(uri);
            builder.show();
    }

谢谢。

        /*In their official site has said need put file type uri that stored in 
phone/SD storage. So Here I just save it and get that uri and then pass it to 
fabric builder.*/

    private void shareViaTwitt() {
        final String myUrlStr = "http://i.stack.imgur.com/2FCsj.png";

                            TweetComposer.Builder builder = null;
                    try {

                        Bitmap bm = getBitmapFromURL(myUrlStr);
                        Uri uri = getImageUri(getContext(), bm);
                        builder = new TweetComposer.Builder(getContext())
                                .text("Sample Text")
                                .image(uri)
                                .url(new URL(""https://www.newurl.....));
                        builder.show();
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (NullPointerException e) {
                        e.printStackTrace();
                    }
            }

        public Uri getImageUri(Context inContext, Bitmap inImage) {
                ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
                String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
                return Uri.parse(path);
            }

            public static Bitmap getBitmapFromURL(String src) {
                try {
                    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                            .permitAll().build();
                    StrictMode.setThreadPolicy(policy);
                    URL url = new URL(src);
                    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();
                    return null;
                }
            }