我怎么可以张贴在Twitter意图Action_send? [英] How can I post on Twitter with Intent Action_send?
本文介绍了我怎么可以张贴在Twitter意图Action_send?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在挣扎着从我的应用程序到Twitter发送文字。
在code以下的工作带来了诸如蓝牙,Gmail的,Facebook和Twitter的应用程序的列表,但是当我选择微博它没有pre灌注,因为我本来期望的文本。
我知道身边有与Facebook这样的问题,但我必须做一些错误的,它不能与Twitter的合作。
意向意图=新的意图(Intent.ACTION_SEND);
intent.setType(text / plain的);
intent.putExtra(Intent.EXTRA_TEXT,示范文本);
startActivity(Intent.createChooser(意向,共享文本));
解决方案
我用这个片段在我的code:
意图tweetIntent =新的意图(Intent.ACTION_SEND);
tweetIntent.putExtra(Intent.EXTRA_TEXT,这是一个考验。);
tweetIntent.setType(text / plain的);
PackageManager packManager = getPackageManager();
名单< ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent,PackageManager.MATCH_DEFAULT_ONLY);
布尔解决= FALSE;
对于(ResolveInfo resolveInfo:resolvedInfoList){
如果(resolveInfo.activityInfo.packageName.startsWith(com.twitter.android)){
tweetIntent.setClassName(
resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name);
解决= TRUE;
打破;
}
}
如果(解决){
startActivity(tweetIntent);
}其他{
意图I =新意图();
i.putExtra(Intent.EXTRA_TEXT,消息);
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse(https://twitter.com/intent/tweet?text=message&via=profileName));
startActivity(ⅰ);
Toast.makeText(这一点,Twitter的应用程序没有找到,Toast.LENGTH_LONG).show();
}
希望它帮助。
I have been struggling to send text from my app to Twitter.
The code below works to bring up a list of apps such as Bluetooth, Gmail, Facebook and Twitter, but when I select Twitter it doesn't prefill the text as I would have expected.
I know that there are issues around doing this with Facebook, but I must be doing something wrong for it to not be working with Twitter.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Example Text");
startActivity(Intent.createChooser(intent, "Share Text"));
解决方案
I'm using this snippet on my code:
Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.putExtra(Intent.EXTRA_TEXT, "This is a Test.");
tweetIntent.setType("text/plain");
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){
startActivity(tweetIntent);
}else{
Intent i = new Intent();
i.putExtra(Intent.EXTRA_TEXT, message);
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://twitter.com/intent/tweet?text=message&via=profileName"));
startActivity(i);
Toast.makeText(this, "Twitter app isn't found", Toast.LENGTH_LONG).show();
}
Hope it helps.
这篇关于我怎么可以张贴在Twitter意图Action_send?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文