FilePicker icon indicating copy to clipboard operation
FilePicker copied to clipboard

App Crash When Done is clicked and no file is selected

Open Ab3id opened this issue 5 years ago • 3 comments

Describe the bug The file picker class crash when there is no file selected and DOne is being clicked

Ab3id avatar May 19 '19 19:05 Ab3id

Sorry for the late reply can you show be the Configurations code.

jaiselrahman avatar Jun 13 '19 14:06 jaiselrahman

@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 }

karimkalunga avatar Aug 06 '19 17:08 karimkalunga

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);
    }
}

Marc-Ferrer-Castillo avatar Mar 21 '20 22:03 Marc-Ferrer-Castillo