In Android Studio using Pdf picker getting the path like this /document/document:15799 how to convert it to base64 or multipart or File. Or how I can get the absolute path of the pdf or docs.
private void selectPdf() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/pdf");
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, true);
try {
startActivityForResult(intent, PDF);
} catch (ActivityNotFoundException e) {
System.out.println("" + e);
}
}
@RequiresApi(api = Build.VERSION_CODES.Q)
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//Log.d(TAG, "onActivityResult: Call..");
if (requestCode == PDF) {
Uri pdfUri = data.getData();
if (!pdfUri.equals("")) {
try {
pdfPath = pdfUri.getPath();
File file = new File(pdfPath);
String absolutePathPdf = file.getAbsolutePath();
}catch (Exception ae){
Log.e(TAG, "onActivityResult: "+ae.toString() );
}
}
}
}