【发布时间】:2014-09-11 16:52:44
【问题描述】:
我可以有意识地打开推特(官方客户端,我不与其他客户端探讨),我可以分享一张图片......只有一张图片
但此时在 twitter 上,它可能会在推文中发布更多图片 (max=4)。
这是我的代码:
public void twitter_intent() {
Intent i = findTwitterClient();
File file1 = new File(Environment.getExternalStorageDirectory() + File.separator + "photo1.png");
File file2 = new File(Environment.getExternalStorageDirectory() + File.separator + "photo2.png");
String mensaje = cxt.getResources().getString(R.string.promocionar_twitter_mensaje,
cxt.getResources().getString(R.string.network_URL_MYWEB));
if (file1.exists())
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file1));
if (file2.exists())
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file2));
i.putExtra(Intent.EXTRA_TEXT, mensaje);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
cxt.startActivity(i);
}
private Intent findTwitterClient() {
final String[] twitterApps = {
// package // name - nb installs (thousands)
"com.twitter.android", // official - 10 000
"com.twidroid", // twidroyd - 5 000
"com.handmark.tweetcaster", // Tweecaster - 5 000
"com.thedeck.android" // TweetDeck - 5 000
};
Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.setType("image/png");
final PackageManager packageManager = cxt.getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (int i = 0; i < twitterApps.length; i++) {
for (ResolveInfo resolveInfo : list) {
String p = resolveInfo.activityInfo.packageName;
if (p != null && p.startsWith(twitterApps[i])) {
tweetIntent.setPackage(p);
return tweetIntent;
}
}
}
return null;
}
第二个文件 (photo2) 覆盖第一个。
如何放入一个 URI 倍数文件?我认为这样问题就会得到解决。
对不起,我的英语...
【问题讨论】:
标签: android android-intent twitter