Error de archivo no encontrado después de seleccionar un archivo en android

Quiero abrir un archivo. Pdf en mi app.now android puedo navegar por el archivo pdf y después de navegar por el archivo que estoy recibiendo el archivo no se encontró el error cuando compruebo el archivo existe o no. Ahora, después de seleccionar el archivo mi archivo seleccionado Uri data.getData() es como

content://com.android.externalstorage.documents/document/6333-6131:SHIDHIN.pdf

Y la ruta cuando data.getData().getPath().toString() utilizando data.getData().getPath().toString() es como

/document/6333-6131:SHIDHIN.pdf Aquí está mi código. Por favor, ayúdame.

 // To Browse the file Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("application/pdf"); startActivityForResult(intent, PICK_FILE_REQUEST); 

Después de seleccionar el archivo

 //onActivityResult public void onActivityResult(final int requestCode, int resultCode, Intent data) { try { switch (requestCode) { case PICK_FILE_REQUEST: if (resultCode == RESULT_OK) { try { Uri fileUri = data.getData(); String path = fileUri.getPath().toString(); File f = new File(path); if (f.exists()) { System.out.println("\n**** Uri :> "+fileUri.toString()); System.out.println("\n**** Path :> "+path.toString()); final Intent intent = new Intent(MainActivity.this, ViewPdf.class); intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path); startActivity(intent); } else { System.out.println("\n**** File Not Exist :> "+path); } } catch (Exception e) { ShowDialog_Ok("Error", "Cannot Open File"); } } break; } } catch (Exception e) { } } 

Esta no es la respuesta sino una solución.

 File file = new File("some_temp_path"); # you can also use app's internal cache to store the file FileOutputStream fos = new FileOutputStream(file); InputStream is = context.getContentResolver().openInputStream(uri); byte[] buffer = new byte[1024]; int len = 0; try { len = is.read(buffer); while (len != -1) { fos.write(buffer, 0, len); len = is.read(buffer); } fos.close(); } catch (IOException e) { e.printStackTrace(); } 

Pase la ruta absoluta de este archivo a su actividad.

 button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { File pdfFile = new File(Environment.getExternalStorageDirectory(), "Case Study.pdf"); try { if (pdfFile.exists()) { Uri path = Uri.fromFile(pdfFile); Intent objIntent = new Intent(Intent.ACTION_VIEW); objIntent.setDataAndType(path, "application/pdf"); objIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(objIntent); } else { Toast.makeText(MainActivity.this, "File NotFound", Toast.LENGTH_SHORT).show(); } } catch (ActivityNotFoundException e) { Toast.makeText(MainActivity.this, "No Viewer Application Found", Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } } }); 
  • OpenCV Android imwrite darme una imagen azul
  • Llame a onSaveInstanceState sin llamar a super.onSaveInstanceState (outState)
  • El signo de interrogación me parece nuevo
  • Android: Bitmap a Byte Array y espalda: SkImageDecoder :: Factory devuelto null
  • Java.lang.IllegalStateException: No se pudo leer la fila 0, col 0 de CursorWindow
  • Método de cifrado para iPhone y Android
  • Transmisión de datos a través de la intención utilizando Serializable
  • HttpResponse a la longitud de cadena 0 se devuelve
  • ¿Cómo puedo solucionar el error de Android Firebase "Default FirebaseApp no ​​se inicializa en este proceso"?
  • La eliminación de elementos ListView cambia la altura de los elementos
  • ¿Puedo desarrollar para Android en algo distinto de Java?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.