Android的推出Twitter的意图 [英] Android launch Twitter intent
本文介绍了Android的推出Twitter的意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用的是code以下为开展微博的意图,但不工作。我有Twitter的应用程序安装在我的手机上。需要帮助!
意图shareIntent =新的意图(android.content.Intent.ACTION_SEND);
shareIntent.setType(text / plain的);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,内容分享);
PackageManager下午= contexto.getPackageManager();
名单< ResolveInfo> activityList = pm.queryIntentActivities(shareIntent,0);
对于(最终ResolveInfo应用程序:activityList){
如果(com.twitter.android.PostActivity.equals(app.activityInfo.name)){
最后ActivityInfo活性= app.activityInfo;
最终的组件名名称=新的组件名(activity.applicationInfo.packageName,activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(名称);
contexto.startActivity(shareIntent);
打破;
}
}
获取异常,当我尝试调用活动:
android.content.ActivityNotFoundException:无法找到明确的活动类{com.twitter.android/com.twitter.android.PostActivity};有你宣布你的AndroidManifest.xml这个活动?
解决方案
通常情况下发动用户的饲料
意向意图= NULL;
尝试 {
//获取Twitter的应用程序如果可能的话
。this.getPackageManager()getPackageInfo(com.twitter.android,0);
意图=新的意图(Intent.ACTION_VIEW,Uri.parse(微博://用户USER_ID = USERID?));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}赶上(例外五){
//没有Twitter的应用程序,恢复到浏览器
意图=新的意图(Intent.ACTION_VIEW,Uri.parse(https://twitter.com/USERID_OR_PROFILENAME));
}
this.startActivity(意向);
有关邮政意向
意图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);
}其他{
Toast.makeText(这一点,Twitter的应用程序没有找到,Toast.LENGTH_LONG).show();
}
I use the code below for launching twitter intent but is not working. I have the twitter app installed on my phone. Need help!
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Content to share");
PackageManager pm = contexto.getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
if ("com.twitter.android.PostActivity".equals(app.activityInfo.name)) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
contexto.startActivity(shareIntent);
break;
}
}
Getting exception when i try to call the activity:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.twitter.android/com.twitter.android.PostActivity}; have you declared this activity in your AndroidManifest.xml?
解决方案
Typically for launching a user's feed
Intent intent = null;
try {
// get the Twitter app if possible
this.getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USERID"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch (Exception e) {
// no Twitter app, revert to browser
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/USERID_OR_PROFILENAME"));
}
this.startActivity(intent);
For Post Intent
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{
Toast.makeText(this, "Twitter app isn't found", Toast.LENGTH_LONG).show();
}
这篇关于Android的推出Twitter的意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文