gpt4 book ai didi

Android通过intent发送Twitter私信

转载 作者:太空宇宙 更新时间:2023-11-03 10:21:28 25 4
gpt4 key购买 nike

我正在尝试从我的应用程序打开 Twitter,当 Twitter 打开时,显示带有用户名信息和一些文本(消息)的直接消息窗口,因此应用程序的用户只需要阅读消息,如果他修改它想要并点击发送。

我有以下代码正在编写推文。如果未安装 Twitter 应用程序,它将尝试从网络浏览器打开 Twitter。 缺少的部分是准备来自原生 Twitter 应用程序的直接消息。

    try{
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "It's a Tweet!" + "#MyApp");
intent.setType("text/plain");
final PackageManager pm = getPackageManager();
final List<?> activityList = pm.queryIntentActivities(intent, 0);
int len = activityList.size();
for (int i = 0; i < len; i++) {
final ResolveInfo app = (ResolveInfo) activityList.get(i);
Log.i("APP",app.activityInfo.name);
if ("com.twitter.applib.PostActivity".equals(app.activityInfo.name)) {
final ActivityInfo activity=app.activityInfo;
final ComponentName x=new ComponentName(activity.applicationInfo.packageName, activity.name);
intent=new Intent(Intent.ACTION_SEND);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
intent.setComponent(x);
intent.putExtra(Intent.EXTRA_TEXT, "blah blah" );
startActivity(intent);
break;
}
}
} catch(final ActivityNotFoundException e) {
Log.i("Twitter intent", "no twitter native", e );
String usernameWeb="https://twitter.com/direct_messages/create/"+user;
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(usernameWeb)))
}

谢谢!

最佳答案

 try {
Intent openNewIntent = new Intent();
String mPackage = "com.twitter.android";
String mClass = ".DMActivity";
openNewIntent.setComponent(new ComponentName(mPackage,mPackage+mClass));
openNewIntent.putExtra("user_ids", new long[]{follower_uid});
openNewIntent.putExtra("keyboard_open", true);
startActivity( openNewIntent);
} catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/direct_messages/create/" + screen_name)));
//e.printStackTrace();
}

关于Android通过intent发送Twitter私信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20243614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com