FilePicker
FilePicker copied to clipboard
App Crash When Done is clicked and no file is selected
Describe the bug The file picker class crash when there is no file selected and DOne is being clicked
Sorry for the late reply can you show be the Configurations
code.
@Ab3id for a workaround you can check if the list is null in your onActivityResult method. It's a late comment but I hope this helps someone.
ArrayList<MediaFile> list = data.getParcelableArrayListExtra(MEDIA_FILES);
if (list != null && list.size() > 0) {
// Do something
}
private static final int ERROR_REQUEST_CODE = -1;
private static final int BUSCAR_IMATGE = 0;
private static final int BUSCAR_VIDEO = 1;
private static final int BUSCAR_SO = 2;
...
if (resultCode == RESULT_OK) {
// Selected files from normal file pick
Uri uri = data.getData();
// Selected files from FilePickerActivity
ArrayList<MediaFile> fitxers = data.getParcelableArrayListExtra(FilePickerActivity.MEDIA_FILES);
// Intent
Intent intent = null;
// If ArrayList<MediaFile> fitxers is null
if (fitxers != null && fitxers.size() == 0) {
requestCode = ERROR_REQUEST_CODE;
}
switch(requestCode){
// Image
case BUSCAR_IMATGE:
if (edicio){
intent = new Intent (this, EditarImagen.class).setData(uri);
}
else{
intent = new Intent (this, MostrarImagen.class).setData(uri);
}
break;
// Audio
case BUSCAR_SO:
// Si es vol editar
if (edicio){
}
// Només visualitzat
else{
intent = new Intent (this, MostrarVideo.class).setData(fitxers.get(0).getUri());
}
break;
// video
case BUSCAR_VIDEO:
if (edicio){
intent = new Intent (this, EditarVideo.class).setData(fitxers.get(0).getUri());
intent.putExtra("RUTA", fitxers.get(0).getPath());
}
else{
intent = new Intent (this, MostrarVideo.class).setData(fitxers.get(0).getUri());
}
break;
default:
Toast.makeText(MainActivity.this, "Any file selected", Toast.LENGTH_LONG).show();
break;
}
// Starts activity
if (intent != null){
startActivity(intent);
}
}