//调用以下方法,打开本地PDF文件 private void loadPdfFile(){ String FILE_TYPE = "application/pdf"; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy(builder.build()); } Intent intent = new Intent(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @SuppressLint("SdCardPath") Uri uri = Uri.fromFile(new File("/mnt/sdcard/Download/test.pdf")); //PDF文件的路径 intent.setDataAndType(uri, FILE_TYPE); try { //开启界面 this.startActivity(intent); } catch (Exception e) { Log.d("exception: " + e); } }
打开本地PDF文件的方法
最新推荐文章于 2024-06-21 10:49:39 发布