如何在android中将图片发布到twitter

我想将我的应用程序中创建的图像发布到twitter。 我不知道该怎么做,我想知道是否有适用于Facebook的titter SDK? 提前致谢

首先,您需要在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(); 

查看本教程了解更多详细信息。

我想你想在Android中实现共享意图。

用户“Second”的答案和代码示例看起来是适用的。

 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")); 

您可以使用Intent在Twitter上发布图像,您可以从此处下载完整的源代码下载完整的源代码

 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”));