Android Intent.ACTION_VIEW

拟墨画扇 提交于 2019-12-22 09:04:45

问题


I need to user choice their own player to play video and I try

public class VideoViewActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String videoUrl = "http://someurl/video.mp4";
        Intent i = new Intent(Intent.ACTION_VIEW);  
        i.setData(Uri.parse(videoUrl));  
        startActivity(i); 
}

But in my example activity open browser not a list of current installed player. Which option of Intent I should use? Is it possible?


回答1:


Please try below code.

String videoUrl = "http://someurl/video.mp4";
Intent i = new Intent(Intent.ACTION_VIEW);  
i.setDataAndType(Uri.parse(videoUrl),"video/mp4");  
startActivity(i); 



回答2:


The schema is "http", so the webview will be open.

this is a stream video, try to download it firstly. and then open it.



来源:https://stackoverflow.com/questions/10430073/android-intent-action-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!