您的位置:首页 > 移动开发 > Android开发

Xamarin.Android - 下载pdf和视频到应用空间并打开

2014-09-02 05:55 726 查看
1. 下载创建本地应用内文件时,创建模式必须为 FileCreationMode.WorldReadable
Stream fos = OpenFileOutput(pdfName, FileCreationMode.WorldReadable);
            using (fos)
            {
                fos.Write(fileBytes,0,fileBytes.Length);
            }


2. 调用pdf 应用打开pdf文件
Java.IO.File pdfFile = Application.Context.GetFileStreamPath(pdfName); 
            if (pdfFile.Exists())
            {
                Android.Net.Uri path = Android.Net.Uri.FromFile(pdfFile);

                Intent intent = new Intent(Intent.ActionView);
                intent.SetDataAndType(path, "application/pdf");
                intent.SetFlags(ActivityFlags.NewTask);

                try
                {
                    Application.Context.StartActivity(intent);
                }
                catch (ActivityNotFoundException ex)
                {
                    System.Diagnostics.Debug.WriteLine("no app installed to view the pdf");
                }
            }


3. 使用VideoView播放视频
videoView.SetVideoPath(internalPath);
            videoView.Start();

参考:http://stackoverflow.com/questions/3038474/can-a-videoview-play-a-video-stored-on-internal-storage
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: