Skip to content

Instantly share code, notes, and snippets.

@ipcjs
Created August 25, 2014 02:46
Show Gist options
  • Save ipcjs/35c576593d530f0188d6 to your computer and use it in GitHub Desktop.
Save ipcjs/35c576593d530f0188d6 to your computer and use it in GitHub Desktop.
用intent调用第三方Twitter客户端
public void send() {
// 第三方应用列表
String[] twitterApps = { "com.twitter.android", "com.twidroid", "com.handmark.tweetcaster", "com.thedeck.android", "org.mariotaku.twidere" };
List<Intent> targetList = new ArrayList<Intent>();
Intent canSendIntent = new Intent(Intent.ACTION_SEND);
canSendIntent.setType("image/*");
List<ResolveInfo> resolveList = context.getPackageManager().queryIntentActivities(canSendIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (!resolveList.isEmpty()) {
for (ResolveInfo resolveInfo : resolveList) {
String packageName = resolveInfo.activityInfo.packageName;
// System.out.println(packageName);
for (String appName : twitterApps) {
if (appName.equals(packageName)) {
Intent target = new Intent(Intent.ACTION_SEND);
target.setType("image/*");
target.putExtra(Intent.EXTRA_TEXT, str);
target.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imgPath)));
target.setPackage(packageName);
targetList.add(target);
}
}
}
if (targetList.size() > 0) {
Intent intentChooser = Intent.createChooser(targetList.remove(0), context.getString(R.string.select_app_to_share));
intentChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetList.toArray(new Parcelable[] {}));
intentChooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// 用第三方应用分享
context.startActivity(intentChooser);
return;
}
}
// 用自带分享
sendByREST();
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment