6

これまでのところ、stackoverflow の投稿で検索したところ、共有のポップアップ ダイアログを表示せずに、テキストを Twitter に直接共有できます。つまり、ボタンをクリックすると、Twitter アプリに直接リダイレクトされ、テキストが表示されます。

私の唯一の問題は、http 画像を twitter に直接共有する必要があることです。

以下に、これまでに試したコードを投稿しました。

ユーザーアダプター.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);

上記のコードでは、テキストは twitter で正しく表示されていますが、画像は http url で表示されています。

リンクを表示せずに画像をTwitterアプリに直接共有する方法を知っている人は誰でも。

4

4 に答える 4

1

あなたは私のためにこれを試すことができます

画像ウリ:

File myImageFile = new File("/path/to/image");
Uri myImageUri = Uri.fromFile(myImageFile);

インテントビルダー

TweetComposer.Builder builder = new TweetComposer.Builder(this)
   .text("just setting up my Fabric.")
   .image(myImageUri);
builder.show();

これを build.gradle の依存関係に追加します:

dependencies {
 compile('com.twitter.sdk.android:tweet-composer:1.0.5@aar') {
    transitive = true;
 }
}
于 2016-08-08T08:38:18.527 に答える
0

これはあなたが必要とするものです

intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file);
于 2016-08-08T06:13:27.550 に答える
0

電話するには:

new PostPicture(MyActivity.this).execute("IMAGE_URL");

投稿画像:

private class PostPicture extends AsyncTask<String, Void, File> {
    private final Context context;

    public PostPicture(Context context) {
        this.context = context;
    }

    @Override
    protected File doInBackground(String... params) {

        FutureTarget<File> future = Glide.with(getApplicationContext())
                .load(params[0])
                .downloadOnly(600, 600);

        File file = null;
        try {
            file = future.get();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return file;
    }

    @Override
    protected void onPostExecute(File result) {
        if (result == null) {
            return ;
        }

        Uri uri = FileProvider.getUriForFile(getApplicationContext(), 
         getApplicationContext().getPackageName(), result);
        postIt(uri);
    }

    private void postIt(Uri result) {
        TweetComposer.Builder builder = new TweetComposer.Builder(this)
                .text("Post Image from URl.")
                .image(result);
        builder.show();
    }
}
于 2016-08-09T12:06:01.387 に答える