3

I successfully shared text/img on twitter with my android application, but now I've need to share VIDEO on Twitter via my app. Is there any possible lib to achieve that? Any suggestions on how to share video on twitter via my application are welcome.

PS: A link to some tutorial would be great.

ark
  • 553
  • 2
  • 11
  • 19

2 Answers2

1

Improvising the AndroidEnthusiastic's answer,below is working code for Sharing video on twitter via android app

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;
    }


 }

where filepath is the path of video stored in device storage like "/storage/emulated/0/Videos/VID_20151011_115238.mp4"

Community
  • 1
  • 1
Android Developer
  • 9,157
  • 18
  • 82
  • 139
  • i have posted video using your code but i need the call back of that uploaded video because i need that postid. It is not giving any resposne. – Rahul Hawge Apr 10 '16 at 12:48
  • **com.twitter.android.composer.ComposerActivity** didn't find this class, instead i have found this **com.twitter.composer.SelfThreadComposerActivity** but this is not post my video – Mohammad nabil Apr 11 '18 at 13:20
0

it's working code. please go through it.

    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 manifest

             <intent-filter>
             <action android:name="android.intent.action.MAIN" />
            <data android:mimeType="image/*" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>