I simply try to pass an additional value through an ACTION_OPEN_DOCUMENT_TREE Intent and I can't manage it. I need to show the tree dialog, so the user can select a folder and I have to pass some additional info. I already used this passing mechanism with other intents and fear that this doesn't work for the special intent ACTION_OPEN_DOCUMENT_TREE ?!
I start the intent and pass the value simplevalue as follow: Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
String sOperations="simplevalue";
intent.putExtra("simplevalue", sOperations);
startActivityForResult(intent, 42);
I try to receive the simplevalue as follow:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if (requestCode == REQUEST_QUICKLIST) {
if (resultCode == Activity.RESULT_OK) {
if(requestCode==42){
String simplevalue="";
simplevalue=data.getStringExtra("simplevalue"); // <-- is null
Bundle extras = data.getExtras(); // <- is null
if(extras == null) {
simplevalue= null;
} else {
simplevalue= extras.getString("simplevalue");
}
the simplevalue and the bundle extras are null when debugging. Howto pass a simple string with the ACTION_OPEN_DOCUMENT_TREE Intent ?
On another class you can get simplevalue using,
Intent intent = getIntent();
String simplevalue = intent.getStringExtra("simplevalue");
I think that the intent we pass to the startActivityForResult is not the same one which invokes the onActivityResult. Therefore it doesn't contains the values you specified.
I think we can manage it using an intermediate activity which accepts and stores your values passed through the intent and start the intent
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
There onActivityResult you can put the stored values the result intent and provide it as your intermediate activities result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With