推特文字和图片

时间:2013-01-26 09:07:14

标签: android android-intent twitter

遵循这个简单的代码:

String tweetUrl = "https://twitter.com/intent/tweet?text=PUT TEXT HERE &url="+"https://www.google.com";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));

它可以与那些文字和图像分享吗?不使用twitter4j库。

谢谢!

1 个答案:

答案 0 :(得分:0)

此代码的作用是查询与Intent.ACTION_SEND匹配的所有活动,然后搜索“com.twitter.android.PostActivity”意图。

try{
intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.setType("text/plain");
final PackageManager pm = context.getPackageManager();
final List activityList = pm.queryIntentActivities(intent, 0);
    int len =  activityList.size();
for (int i = 0; i < len; i++) {
    final ResolveInfo app = activityList.get(i);
    if ("com.twitter.android.PostActivity".equals(app.activityInfo.name)) {
        final ActivityInfo activity=app.activityInfo;
        final ComponentName name=new ComponentName(activity.applicationInfo.packageName, activity.name);
        intent=new Intent(Intent.ACTION_SEND);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        intent.setComponent(name);
        intent.putExtra(Intent.EXTRA_TEXT, message);
        context.startActivity(intent);
        break;
    }
}
 }   catch(final ActivityNotFoundException e) {
     Log.i("mufumbo", "no twitter native",e );
      }