Estoy intentando crear un pdf dentro de un boton de un fragment de la siguiente manera:
btnPdf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
int permissionCheck = ContextCompat.checkSelfPermission(
getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
Log.i("Mensaje", "No se tiene permiso para leer.");
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 225);
} else {
PdfDocument pdfDocument = new PdfDocument();
Paint paint = new Paint();
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(400,600,1).create();
PdfDocument.Page page = pdfDocument.startPage(pageInfo);
Canvas canvas = page.getCanvas();
canvas.drawText("ejemplo",40,50,paint);
pdfDocument.finishPage(page);
File file = new File(Environment.getExternalStorageDirectory(),"/ejemplo");
try {
pdfDocument.writeTo(new FileOutputStream(file));
}catch (IOException e){
e.printStackTrace();
}
pdfDocument.close();
}
}
}
});
Los permisos en el manifest esta para el write and read external storage, como errror me sale
W/System.err: java.io.FileNotFoundException: /storage/emulated/0/ejemplo: open failed: EACCES (Permission denied)
y no crea nada, ademas para añadir; en otro fragment guardo imagenes en el dispositivo con exito pero aun asi no se logra guardar el pdf
EL manifest
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE " />