I am trying to make an app to view files in a folder (the apps storage folder on external storage located at /storage/emulated/0/Android/data/app_name)
However I can not view the folder. I would like to automatically navigate to this folder when the user clicks the button
Setting the root path does nothing.
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
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 {
Button btFile;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btFile = findViewById(R.id.button);
btFile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, FilePickerActivity.class);
intent.putExtra(FilePickerActivity.CONFIGS,
new Configurations.Builder()
.setCheckPermission(true)
.setShowFiles(true)
.setShowImages(false)
.setShowAudios(false)
.setShowVideos(false)
.setMaxSelection(1)
.setSuffixes("txt","pdf","doc","docx")
.setSkipZeroSizeFiles(true)
.setRootPath("/storage/emulated/0/Android/data/")
.build());
startActivityForResult(intent,102);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK && data !=null){
ArrayList<MediaFile> mediaFiles = data.getParcelableArrayListExtra(
FilePickerActivity.MEDIA_FILES
);
String path = mediaFiles.get(0).getPath();
if(requestCode == 102){
String s = "File Path : " + path;
Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();
}
}
}
}
question from:
https://stackoverflow.com/questions/65866180/how-to-target-a-specific-folder-to-open-in-file-picker 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…