我想在我的Android原生应用中添加一个图像以及一些文本。我看到几个建议意图分享的链接。但我不想要那个。我如何使用twitter4j获得这个。我发现了一个允许图像共享的twitpic jar。它是有效的,但它也分享在Facebook,它在tweet中显示twitpic。我们可以避免Facebook共享吗?或者是否可以使用twitter4j_media_support jar共享图像?
答案 0 :(得分:1)
查看this教程。
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();
Twitter twitter = new TwitterFactory(configuration).getInstance();
StatusUpdate status = new StatusUpdate(message);
status.setMedia(file); // set the image to be uploaded here.
twitter.updateStatus(status);
答案 1 :(得分:0)
使用此代码
private void sendShareTwit() {
try {
Intent tweetIntent = new Intent(Intent.ACTION_SEND);
String filename = "<file path>/twitter_image.jpg";
File imageFile = new File(Environment.getExternalStorageDirectory(), filename);
tweetIntent.putExtra(Intent.EXTRA_TEXT, twitter_share_text);
tweetIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile));
tweetIntent.setType("image/jpeg");
PackageManager pm = getActivity().getPackageManager();
List<ResolveInfo> lract = pm.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY);
boolean resolved = false;
for (ResolveInfo ri : lract) {
if (ri.activityInfo.name.contains("twitter")) {
tweetIntent.setClassName(ri.activityInfo.packageName,
ri.activityInfo.name);
resolved = true;
break;
}
}
startActivity(resolved ?
tweetIntent :
Intent.createChooser(tweetIntent, "Choose one"));
} catch (final ActivityNotFoundException e) {
System.out.rintln( "You don't seem to have twitter installed on this device", Toast.LENGTH_SHORT));
}
}