我想将在我的应用中创建的图片发布到twitter。我不知道怎么做这个,我想知道是否有适用于Facebook的titter SDK? 提前致谢
答案 0 :(得分:3)
首先,你需要在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了解详情。
答案 1 :(得分:0)
我认为你想在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"));
答案 2 :(得分:0)
您可以使用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”));