Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass additional intent values to a ACTION_OPEN_DOCUMENT_TREE Intent

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 ?

like image 879
mcfly soft Avatar asked Apr 18 '15 07:04

mcfly soft


2 Answers

On another class you can get simplevalue using,

 Intent intent = getIntent();
 String simplevalue = intent.getStringExtra("simplevalue");
like image 190
Akshay Shinde Avatar answered Nov 15 '22 01:11

Akshay Shinde


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.

like image 36
Ansal Ali Avatar answered Nov 15 '22 00:11

Ansal Ali