我只需通过Tweet分享图片。
这是我的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UILabel *inTime = [[UILabel alloc] initWithFrame:CGRectMake(70.0, 12.0, 50.0, 20.0)];
[inTime setTag:1];
[inTime setBackgroundColor:[UIColor lightGrayColor]]; // transparent label background
[inTime setFont:[UIFont boldSystemFontOfSize:11.0]];
// custom views should be added as subviews of the cell's contentView:
[cell.contentView addSubview:inTime];
UILabel *outTime = [[UILabel alloc] initWithFrame:CGRectMake(140.0, 12.0, 50.0, 20.0)];
[outTime setTag:2];
[outTime setBackgroundColor:[UIColor lightGrayColor]]; // transparent label background
[outTime setFont:[UIFont boldSystemFontOfSize:11.0]];
// custom views should be added as subviews of the cell's contentView:
[cell.contentView addSubview:outTime];[(UILabel *)[cell.contentView viewWithTag:1] setText:[SlotsAvailable objectAtIndex:indexPath.row]];
[(UILabel *)[cell.contentView viewWithTag:2] setText:[slot_time_out objectAtIndex:indexPath.row]];
}
我想要的是什么:
如何通过Twitter或直接消息通过Twitter分享?
如何更改标题&共享项目的图标。 Ex Twitter分享项目从“Android系统”到“推特”?
答案 0 :(得分:4)
我无法将Tweet和Direct Message都放到前面,但是下面的代码会让你在那里找到一个。实际上你可以把两者都放在前面,但两者都出现了同名“Tweet”所以它的种类无法使用。
我还包括facebook,insta和tumblr。
要使用com.twitter.android.composer.ComposerActivity
替换com.twitter.android.DMActivity
,请使用直接消息代替推文。为两者添加另一个'if'用于DMActivity。
不能肯定地说,但我认为您不能更改应用程序包的图标。
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/jpeg");//("text/plain");
Uri uri = Uri.fromFile(outFile);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(shareIntent, 0);
for (ResolveInfo resolveInfo : resInfo) {
String packageName = resolveInfo.activityInfo.packageName;
Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
targetedShareIntent.setType("image/jpeg");
targetedShareIntent.putExtra(Intent.EXTRA_STREAM, uri);
if(TextUtils.equals(packageName,"com.facebook.katana")|TextUtils.equals(packageName,"com.instagram.android")
|TextUtils.equals(packageName,"com.tumblr")) {
targetedShareIntent.setPackage(packageName);
targetedShareIntents.add(targetedShareIntent);
}
if(TextUtils.equals(resolveInfo.activityInfo.name,"com.twitter.android.composer.ComposerActivity")) {
targetedShareIntent.setPackage(packageName);
targetedShareIntent.setClassName(
resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name);
targetedShareIntents.add(targetedShareIntent);
}
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
答案 1 :(得分:0)
撰写新推文:
public static Intent getTwitterShareIntent(Context context) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setClassName("com.twitter.android",
"com.twitter.composer.ComposerShareActivity");
return shareIntent;
}