【问题标题】:How to post image to twitter in android如何在android中将图像发布到twitter
【发布时间】:2013-06-10 05:14:13
【问题描述】:

我想将在我的应用中创建的图像发布到 Twitter。我不知道该怎么做,我想知道是否有一个像 Facebook 一样的用于 Titter 的 SDK? 提前致谢

【问题讨论】:

    标签: java android facebook twitter


    【解决方案1】:

    首先你需要在 twitter 上创建一个应用

    这是在 Twitter 上发布消息的代码

     ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.setOAuthConsumerKey(context.getResources().getString(R.string.twitter_consumer_key));
            configurationBuilder.setOAuthConsumerSecret(context.getResources().getString(R.string.twitter_consumer_secret));
            configurationBuilder.setOAuthAccessToken(LoginActivity.getAccessToken((context)));
            configurationBuilder.setOAuthAccessTokenSecret(LoginActivity.getAccessTokenSecret(context));
            Configuration configuration = configurationBuilder.build();
            final Twitter twitter = new TwitterFactory(configuration).getInstance();
    
            new Thread(new Runnable() {
    
                    private double x;
    
                    @Override
                    public void run() {
                            boolean success = true;
                            try {
                                    x = Math.random();
                                    twitter.updateStatus(message +" "+x);
                            } catch (TwitterException e) {
                                    e.printStackTrace();
                                    success = false;
                            }
    
                            final boolean finalSuccess = success;
    
                            callingActivity.runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                            postResponse.onFinsihed(finalSuccess);
                                    }
                            });
    
                    }
            }).start(); 
    

    查看tutorial了解更多详情。

    【讨论】:

      【解决方案2】:

      我认为您想在 Android 中实现共享意图。

      这个answer and code example by user "Second" looks applicable.

      Intent share = new Intent(Intent.ACTION_SEND);
      share.setType("image/jpeg");
      
      share.putExtra(Intent.EXTRA_STREAM,
         Uri.parse("file:///sdcard/DCIM/Camera/myPic.jpg"));
      
      startActivity(Intent.createChooser(share, "Share Image"));
      

      【讨论】:

        【解决方案3】:

        您可以使用 Intent 在 Twitter 上发布图片,也可以从这里下载完整的源代码 download full source code

        Bitmap b =BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType(“image/jpeg”);
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        b.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
        String path = MediaStore.Images.Media.insertImage(getContentResolver(), b, “Title”, null);
        Uri imageUri = Uri.parse(path);
        share.putExtra(Intent.EXTRA_STREAM, imageUri);
        startActivity(Intent.createChooser(share, “Select”));
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-01-15
          • 2015-01-21
          • 1970-01-01
          • 2013-05-04
          • 1970-01-01
          • 2020-10-16
          • 2016-09-12
          相关资源
          最近更新 更多