【问题标题】:video share by intent only play in my own app有意分享的视频仅在我自己的应用中播放
【发布时间】:2018-05-18 11:10:01
【问题描述】:

当我分享视频并在我的默认播放器上而不是在我的应用程序中打开该链接时,我正在使用视频播放器。如何在我的应用上打开该视频。

这是我的代码(在片段类中):

            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT,
                    "Hey check out my app at: "+share_video);
            sendIntent.setType("text/plain");
            startActivity(sendIntent);

【问题讨论】:

标签: android android-intent share


【解决方案1】:

试试这个:- 你可以使用 createChooser 作为你的意图,它将显示所有能够处理你的意图的应用程序。

例如:-

   Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT,
                    "Hey check out my app at: "+share_video);
            sendIntent.setType("text/plain");

Intent chooser = Intent.createChooser(sendIntent);

    // Verify the intent will resolve to at least one activity
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(chooser);
    }

【讨论】:

    【解决方案2】:

    使用视频视图: 对于流式传输链接,您可以执行以下操作:

        String LINK = "type_here_the_link";
          VideoView mVideoView  = (VideoView) findViewById(R.id.videoview);
          MediaController mc = new MediaController(this);
          mc.setAnchorView(videoView);
          mc.setMediaPlayer(videoView);
          Uri video = Uri.parse(LINK);
          mVideoView.setMediaController(mc);
          mVideoView.setVideoURI(video);
          mVideoView.start();
    
    
    >or for local video u can do something like:
    
    
    
    
            VideoView videoView =(VideoView)findViewById(R.id.videoView1);  
    
                   //Creating MediaController  
      MediaController mediaController= new MediaController(this);  
       mediaController.setAnchorView(videoView);          
    
                              //specify the location of media file  
                           Uri uri=Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/media/1.mp4");          
    
                              //Setting MediaController and URI, then starting the videoView  
                           videoView.setMediaController(mediaController);  
                           videoView.setVideoURI(uri);          
                           videoView.requestFocus();  
                           videoView.start();  
    
    
    
    > U can visit the link for more understanding:
    > https://www.javatpoint.com/playing-video-in-android-example
    

    【讨论】:

      猜你喜欢
      • 2014-07-27
      • 1970-01-01
      • 2016-11-23
      • 1970-01-01
      • 1970-01-01
      • 2014-12-09
      • 2013-10-22
      • 1970-01-01
      • 2016-07-09
      相关资源
      最近更新 更多