正在使用action_send
Intent在twitter上与android共享文本和图片。我在onActivityResult
获得了成功和 dulipcate 推文的成功回复代码。任何人都可以建议我如何处理这个问题。
我的代码
Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.putExtra(Intent.EXTRA_TEXT,"This is a Test.");
tweetIntent.putExtra(Intent.EXTRA_STREAM,pictureUri);
tweetIntent.setType("image/jpeg");
PackageManager packManager = getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent,PackageManager.MATCH_DEFAULT_ONLY);
boolean resolved = false;
for (ResolveInfo resolveInfo : resolvedInfoList) {
if (resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) {
tweetIntent.setClassName(resolveInfo.activityInfo.packageName,resolveInfo.activityInfo.name);
resolved = true;
break;}}
if (resolved) {
startActivityForResult(tweetIntent, 2);
} else {
Toast.makeText(Store_Detail_Activity.this,"Twitter app isn't found",Toast.LENGTH_LONG).show();
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if(resultCode==0)
Toast.makeText(Store_Detail_Activity.this,"Tweet cancelled",Toast.LENGTH_LONG).show();
else if(resultCode==-1) // Success Result Code
Toast.makeText(Store_Detail_Activity.this,"Tweeted successfully",Toast.LENGTH_LONG).show();
}
答案 0 :(得分:1)
根据您的代码,我知道您正在打开Twitter应用程序来做推文。 所以,我不知道那样,但是如果你准备使用Tweeter4J api做推文那么你就可以清楚地知道什么是成功的推文,哪一个是重复的。
请查看以下代码以了解推文。
public void updateStatus(final StatusUpdate status) throws Exception {
mProgressDlg.setMessage("Posting...");
mProgressDlg.show();
new Thread(new Runnable() {
@Override
public void run() {
int i = 0;
try {
mTwitter.updateStatus(status);
i = 0;
} catch (TwitterException e) {
e.printStackTrace();
System.out.println("Not Posted: In Catch");
message = e.getErrorMessage();
System.out.println("MESSAGE:::: "+message);
//asdasd
//Toast.makeText(context, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
//e.getMessage();
i= 1;
}
mPostHandler.sendEmptyMessage(i);
}
}).start();
}
再次告诉您,只有您使用Twitter4J库在Twitter上发推文才会有用。
感谢。享受编码.. :)