打开警报框以在android中打开下载器或视频

时间:2014-02-12 07:19:33

标签: android

我在我的活动中添加了这个条件

else if (url.contains("googlevideo.com")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "video/*");
startActivity(intent);

我必须打开一个可以帮助用户选择下载/观看的Dilog

从哪个下载开始从该网址下载

和观看按钮开始打开视频代码中的视频。

1 个答案:

答案 0 :(得分:0)

代码对话框:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
    //builder.setTitle(" MY_TEXT");
    builder.setMessage("Would you like to see a video?")
    .setView(checkBoxView)
    .setCancelable(false)
    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            //Start the movie
            startVideo();
            dialog.cancel();
        }
    })
    .setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    }).show().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

打开视频的代码:

getWindow().setFormat(PixelFormat.TRANSLUCENT);
final VideoView videoHolder = new VideoView(this);
//if you want the controls to appear
videoHolder.setMediaController(new MediaController(this));
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" 
        + R.raw.documentariesandyou); //do not add any extension
//if your file is named sherif.mp4 and placed in /raw
//use R.raw.sherif
videoHolder.setVideoURI(video);
setContentView(videoHolder);
videoHolder.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

    @Override
    public void onCompletion(MediaPlayer mp) {
        //exits video!
        videoHolder.stopPlayback();
        mp.release();
        finish();
    }
});
videoHolder.start();