我通过我的Android应用程序成功地在Twitter上分享了text/img,但现在我需要通过我的应用程序在Twitter上分享视频。有没有可能的lib来实现它?欢迎任何有关如何通过我的应用程序在Twitter上分享视频的建议。通过Android应用程序在Twitter上分享视频
PS:一些教程的链接会很棒。
我通过我的Android应用程序成功地在Twitter上分享了text/img,但现在我需要通过我的应用程序在Twitter上分享视频。有没有可能的lib来实现它?欢迎任何有关如何通过我的应用程序在Twitter上分享视频的建议。通过Android应用程序在Twitter上分享视频
PS:一些教程的链接会很棒。
它的工作代码。请通过它。
Button b;
String path="video path";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button=(Button)findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,path);
final PackageManager pm = v.getContext().getPackageManager();
final 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);
v.getContext().startActivity(shareIntent);
break;
}
}
}
});
Android清单
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<data android:mimeType="image/*" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
即兴的AndroidEnthusiastic's答案,以下是通过Android应用在Twitter上共享视频时码
File f=new File(filepath);
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("video/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
final PackageManager pm = getActivity().getApplicationContext().getPackageManager();
final List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
if("com.twitter.android.composer.ComposerActivity".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);
getActivity().getApplicationContext().startActivity(shareIntent);
break;
}
}
其中filepath
是存储的视频路径在设备存储器中,如“/storage/emulated/0/Videos/VID_20151011_115238.mp4
”
我已经使用您的代码发布了视频,但我需要回电该上传的视频,因为我需要该postid。它没有给予任何解决办法。 – 2016-04-10 12:48:10