简体   繁体   中英

getting result for startActivityForResult() in normal class

I am working on saving PDF from internet. The class I am using, to download pdf is a normal class "FileChooser.java", not an activity class. Now, I want to open a Activity to browse through the SDCard and return the selected folder path to the "FileChooser" class

I have planned to use the following code

private void getFolder() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
    intent.setType("*/*"); 
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {
        startActivityForResult(
                Intent.createChooser(intent, "Please select the folder"),0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

but i want the result to be in "FileChooser" (Normal Java)class

What should i do, to get the result in "FileChooser" class?

Please guide me.

You can pass the data using setresult() and get the result by using onactivity result().

The tutorial here helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM