Norm Radder wrote:I don't know that Android has a file chooser class. I never found it and finally wrote one for myself.
I'd be very happy if there is now one available.
So I've come round to looking at this again, having fixed all my apps to work with Oreo... it actually looks quite easy -
private static final int CHOOSE_FILE_REQUESTCODE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Uri selectedUri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/AutBuddy/");
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
// intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setDataAndType(selectedUri, "*/db");
Intent i = Intent.createChooser(intent, "File");
startActivityForResult(i, CHOOSE_FILE_REQUESTCODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode){
case CHOOSE_FILE_REQUESTCODE:
if(resultCode==-1){
Uri uri = data.getData();
String filePath = uri.getPath();
Toast.makeText(this, filePath,
Toast.LENGTH_LONG).show();
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
That toasts the file location, which I assume (wont get to code it into an app until tomorrow evening at the earliest) I can just slot into my app.
What I've not got working (although people say this code should do it) is have it start off in the folder that has my db files in it. Any ideas on that?