我在twitter上用我的Android应用程序成功分享了text / img,但现在我需要通过我的应用程序在Twitter上分享VIDEO。是否有任何可能的lib来实现这一目标?有关如何通过我的应用程序在Twitter上分享视频的任何建议都是受欢迎的。
PS:链接到一些教程会很棒。
答案 0 :(得分:1)
即兴创作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
”
答案 1 :(得分:0)
它的工作代码。请仔细阅读。
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>