如何在android中直接分享http图片到twitter?

Luf*_*ffy 6 twitter android android-twitter

到目前为止我在stackoverflow帖子中搜索了,我可以直接将文本分享给twitter,而不显示分享的弹出对话框.这意味着当我点击按钮时,它会直接重定向到Twitter应用程序并显示文本.

我唯一的问题是我必须直接与Twitter分享http图像.

下面我发布了我到目前为止所尝试的代码:

UsersAdapter.java:

// Create intent using ACTION_VIEW and a normal Twitter url:
        String tweetUrl = String.format("https://twitter.com/intent/tweet?text=%s&url=%s",
                urlEncode(strShareText), 
                urlEncode(strShareImageUrl));
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(tweetUrl));

        // Narrow down to official Twitter app, if available:
        List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent, 0);
        for (ResolveInfo info : matches) {
            if (info.activityInfo.packageName.toLowerCase().startsWith("com.twitter")) {
                intent.setPackage(info.activityInfo.packageName);
            }
        }

        context.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,文本在twitter中正确显示.但是在http url中显示了图像.

任何人都知道如何直接分享图像到Twitter应用程序而不显示链接.

Nir*_*tel 5

您可以使用TwitterComposer对话框.

这是示例代码.

TweetComposer.Builder builder = new TweetComposer.Builder(mActivity)
                .text("hello text");
                .image(Uri.parse("https://media-mediatemple.netdna-ssl.com/wp-content/uploads/2016/01/07-responsive-image-example-castle-7-opt.jpg"));
builder.show();
Run Code Online (Sandbox Code Playgroud)

在gradle文件中添加依赖项

compile('com.twitter.sdk.android:twitter:1.8.0@aar') {
        transitive = true;
}
Run Code Online (Sandbox Code Playgroud)