Sunday, October 20, 2019

Multiple File Picker in android

Multiple File Picker Library ,with this a user can pick multiple files for uploading to the server using retrofit or volley..


Dependency used for File Picker

implementation 'com.github.jaiselrahman:FilePicker:1.2.2'



Java File



package com.example.filepicker;

import android.content.Intent;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.jaiselrahman.filepicker.activity.FilePickerActivity;
import com.jaiselrahman.filepicker.config.Configurations;
import com.jaiselrahman.filepicker.model.MediaFile;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    ArrayList<CustomMediaFile> imageArrayList;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==123 && resultCode==RESULT_OK){
            ArrayList<MediaFile> files = data.getParcelableArrayListExtra(FilePickerActivity.MEDIA_FILES);
            //Do something with files
            for (int i=0; i<files.size();i++){
                Log.d("MyPaths",files.get(i).getPath());
            }

        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pickFiles();
            }
        });

    }
    public void pickFiles(){
        imageArrayList = new ArrayList<>();
        Intent filePickerIntent = new Intent(MainActivity.this, FilePickerActivity.class);
        filePickerIntent.putExtra(FilePickerActivity.CONFIGS, new Configurations.Builder()
                .setCheckPermission(true)
                .setMaxSelection(1)
                .setShowImages(false)
                .enableImageCapture(false)
                .setShowVideos(false)
                .setShowAudios(false)
                .setShowFiles(true)
                .setSuffixes(new String[]{"pdf", "doc", "xls"})
                .build());
        startActivityForResult(filePickerIntent, 123);
    }
}

2 comments:

TechMatrite said...

Free Android App Maker is one of the best free utility to create an android application. Cyberflix APK

TechMatrite said...

Going to graduate school was a positive decision for me. I enjoyed the coursework, the presentations, the fellow students, and the professors. And since my company reimbursed 100% of the tuition, the only cost that I had to pay on my own was for books and supplies. Otherwise, I received a free master’s degree. All that I had to invest was my time. https://satta-king.center/

Alert Dialog Box

Alert Dialog Box Android AlertDialog   can be used to display the dialog message with OK and Cancel buttons. It can be used to inter...