Как получить путь к файлам, таким как PDF, image, PPT из средства выбора файлов в android studio (JAVA)?
//case 1: //Result of Log.i("km",path); /content:/com.android.externalstorage.documents/document/primary%3ADCIM%2Fimages.jpeg //what is primary%3ADCIM%2? //Why i'm not getting proper path like documents/document/primary/DCIM/images.jpeg
//case 2: // DocumentFile d = DocumentFile.fromSingleUri(this, uri); // Log.i("fe", "path: " + d.getUri().getPath()); //Result /document/primary:DCIM/images.jpeg //Now getting a colon sign in the path //what is the problem guys? //need proper path like /document/primary/DCIM/images.jpeg //help
Что я уже пробовал:
//creating a file chooser btnSelectFile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String[] mimeTypes = {"image/*", "application/pdf", "application/zip", "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "text/plain" }; //File Chooser Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes); intent.setType("*/*"); startActivityForResult(Intent.createChooser(intent, "Select a file"), PICK_FILE); } }); //OnActivityResult @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (requestCode == PICK_FILE && resultCode == RESULT_OK && data != null) { Uri uri = data.getData(); File fl = new File(uri.toString()); path = fl.getAbsolutePath(); Log.i("km", path); } super.onActivityResult(requestCode, resultCode, data); }