【问题标题】:Share video on twitter via android app通过 android 应用在 Twitter 上分享视频
【发布时间】:2013-02-05 00:18:05
【问题描述】:

我在 Twitter 上与我的 android 应用程序成功分享了 text/img,但现在我需要通过我的应用程序在 Twitter 上分享 VIDEO。是否有任何可能的库来实现这一目标?欢迎任何关于如何通过我的应用程序在 Twitter 上分享视频的建议。

PS:一些教程的链接会很棒。

【问题讨论】:

    标签: android twitter twitter-oauth android-twitter


    【解决方案1】:

    即兴回答AndroidEnthusiastic's,下面是通过安卓应用在推特上分享视频的工作代码

    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。它没有给出任何回应。
    • com.twitter.android.composer.ComposerActivity 没有找到这个类,而是我找到了这个 com.twitter.composer.SelfThreadComposerActivity但这不是发布我的视频
    【解决方案2】:

    这是工作代码。请通过它。

        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>
    

    【讨论】:

      猜你喜欢
      • 2015-08-17
      • 1970-01-01
      • 1970-01-01
      • 2012-12-04
      • 1970-01-01
      • 2018-03-21
      • 1970-01-01
      • 2017-08-30
      • 2012-04-19
      相关资源
      最近更新 更多