如何选择要上载的pdf文件

mum43rcc  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(262)

我有一个可以选择上传图像的代码,但是我想把它改成pdf,当我把mediastore.images改成mediastore.files时,我怎么能把它打上点呢?这里是我的代码

  1. public void sec(View view){
  2. if(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED){
  3. if(ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.READ_EXTERNAL_STORAGE)){
  4. Snackbar.make(view,"Dosyalara Erişim İçin İzin Gerekiyor",Snackbar.LENGTH_INDEFINITE).setAction("İzin ver", new View.OnClickListener() {
  5. @Override
  6. public void onClick(View v) {
  7. permissonLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE);
  8. }
  9. }).show();
  10. }else{
  11. permissonLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE);
  12. }
  13. }else{
  14. Intent intettoFiles=new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  15. activityResultLauncher.launch(intettoFiles);
  16. }
  17. }
  18. public void registerLauncher(){
  19. activityResultLauncher=registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
  20. @Override
  21. public void onActivityResult(ActivityResult result) {
  22. if(result.getResultCode()==RESULT_OK){
  23. Intent intentfromresult=result.getData();
  24. if(intentfromresult!=null){
  25. CVDATA=intentfromresult.getData();
  26. binding.imageView.setImageURI(CVDATA);
  27. }
  28. }
  29. }
  30. });
  31. permissonLauncher=registerForActivityResult(new ActivityResultContracts.RequestPermission(), new ActivityResultCallback<Boolean>() {
  32. @Override
  33. public void onActivityResult(Boolean result) {
  34. if (result) {
  35. Intent intenttoFiles=new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  36. activityResultLauncher.launch(intenttoFiles);
  37. } else{
  38. Toast.makeText(Profil.this, "İzin Gerekiyor!", Toast.LENGTH_SHORT).show();
  39. }
  40. }
  41. });
  42. }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题