本文介绍了Twitter的PostActivity问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个意图已经stoppped工作。这是工作了2个月
2个月前的类名称已经从com.twitter.android.PostActivity到com.twitter.applib.PostActivity改变。我认为这又变了。难道又变了一次又一次?
谁能帮我发布的tweet?
和抱歉我的英语水平
尝试{
getPackageManager()。getPackageInfo(
com.twitter.android,0);
意图twitterIntent =新的意图(
Intent.ACTION_VIEW);
字符串twitterVersionName = getPackageManager()
.getPackageInfo(com.twitter.android
0).versionName;
版本控制CURRENTVERSION =新的版本控制(
twitterVersionName);
版本控制requestedVersion =新的版本控制(
4.1.9);
如果(currentVersion.compareTo(requestedVersion)> -1){
twitterIntent.setClassName(
com.twitter.android
com.twitter.applib.PostActivity);
} 其他 {
twitterIntent.setClassName(
com.twitter.android
com.twitter.android.PostActivity);
}
twitterIntent.putExtra(Intent.EXTRA_TEXT,
tweetText);
startActivity(twitterIntent);
}赶上(的NameNotFoundException E){
尝试 {
startActivity(新意图(
Intent.ACTION_VIEW,
Uri.parse(https://twitter.com/intent/tweet?source=webclient&text=
+ URLEn coder.en code(
tweetText,UTF-8))));
}赶上(UnsupportedEncodingException E1){
e1.printStackTrace();
}
}
解决方案
您不必寻找确切的名称,你可以尝试这样的,
意图shareIntent =新的意图(Intent.ACTION_SEND);
shareIntent.setType(* / *);
shareIntent.putExtra(Intent.EXTRA_TEXT,您的文字在这里);
shareIntent.putExtra(Intent.EXTRA_STREAM,截图);
字符串的appName =推特;
//还可以使用Instagram的,Pinterest的,邮件等的程序的名字。(不是Facebook)
最终PackageManager下午= _activity.getPackageManager();
最后的名单,其中;> activityList = pm.queryIntentActivities(shareIntent,0);
INT的len = activityList.size();
Log.d(标签,长度:+ LEN);
的for(int i = 0; I< LEN;我++)
{
最后ResolveInfo应用=(ResolveInfo)activityList.get(我);
Log.d(关于共享列表的应用程序:+ app.activityInfo.name);
如果((app.activityInfo.name.contains(的appName)))
{
Log.d(标签,发现套餐+ app.activityInfo.name);
最后ActivityInfo活性= app.activityInfo;
最终的组件名名称=新的组件名(activity.applicationInfo.packageName,activity.name);
shareIntent.setComponent(名称);
// TODO改变你的活动在这里
_activity.startActivityForResult(shareIntent,SHARE_REQUEST_ code);
返回;
}
}
//没有发现这样做默认重定向
Log.d(标签,未找到包:);
This intent has stoppped working . It was working for 2 months
2 month ago class name has changed from "com.twitter.android.PostActivity" to "com.twitter.applib.PostActivity" . I think it changed again. Is it changed again again and again ?
Can anyone help me to post tweet ?
and sorry about my english
try {
getPackageManager().getPackageInfo(
"com.twitter.android", 0);
Intent twitterIntent = new Intent(
Intent.ACTION_VIEW);
String twitterVersionName = getPackageManager()
.getPackageInfo("com.twitter.android",
0).versionName;
VersionControl currentVersion = new VersionControl(
twitterVersionName);
VersionControl requestedVersion = new VersionControl(
"4.1.9");
if (currentVersion.compareTo(requestedVersion) > -1) {
twitterIntent.setClassName(
"com.twitter.android",
"com.twitter.applib.PostActivity");
} else {
twitterIntent.setClassName(
"com.twitter.android",
"com.twitter.android.PostActivity");
}
twitterIntent.putExtra(Intent.EXTRA_TEXT,
tweetText);
startActivity(twitterIntent);
} catch (NameNotFoundException e) {
try {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/intent/tweet?source=webclient&text="
+ URLEncoder.encode(
tweetText, "UTF-8"))));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
}
解决方案
You don't need to search for exact name , you can try like this,
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("*/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Your text here");
shareIntent.putExtra(Intent.EXTRA_STREAM, screenShot);
String appName = "twitter";
// use also instagram, pinterest, mail etc for appName.(not facebook)
final PackageManager pm = _activity.getPackageManager();
final List<?> activityList = pm.queryIntentActivities(shareIntent, 0);
int len = activityList.size();
Log.d("Tag","Length: "+len);
for (int i = 0; i < len; i++)
{
final ResolveInfo app = (ResolveInfo) activityList.get(i);
Log.d("Apps on share list: "+ app.activityInfo.name);
if ((app.activityInfo.name.contains(appName)))
{
Log.d("Tag","Found package: "+app.activityInfo.name);
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.setComponent(name);
//TODO change your activity here
_activity.startActivityForResult(shareIntent,SHARE_REQUEST_CODE);
return;
}
}
// not found so make default redirecting
Log.d("Tag","Not Found package: ");
这篇关于Twitter的PostActivity问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!