startActivityForResult not working in Android version 4.4 ( Kitkat version )

最后都变了- 提交于 2019-12-23 03:12:56

问题


Through my application the user can choose a file from the filemanager and process the choosen file ( Example: A PDF document ) for other steps like printing or to email.

To do this I used the below code to display the intent, from which the user can choose a file from file-manager option.

protected void showFileChooser(String title, String type) {
        Log.i(TAG, "FileChooserActivity showFileChooser(title,type)");

        if (TextUtils.isEmpty(title)) title = getString(R.string.select_file);      
        if (TextUtils.isEmpty(type)) type = "*/*";  

        // Implicitly allow the user to select a particular kind of data
        final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 

        // Specify the MIME data type filter (Must be lower case)
        intent.setType(type.toLowerCase()); 

        // Only return URIs that can be opened with ContentResolver
        intent.addCategory(Intent.CATEGORY_OPENABLE);

        // Display intent chooser
        try {
            startActivityForResult(
                    Intent.createChooser(intent, title),6384);
        } catch (android.content.ActivityNotFoundException e) {

            Log.i(TAG,"FileChooserActivity showFileChooser(title,type) Exception" +Log.getStackTraceString(e));
            onFileError(e);
        }
    }

Problem in Android Kitkat version ( 4.4 ) :

Using the above code , I can access all files from the file manager ( i.e., both sub folder's and root folder) in android 4.3 and all android versions except Android 4.4.

In Android 4.4 , I can access files from the root folder, where as I cant access the files from the subfolders. I get java.io.FileNotFoundException as exception.

Note: I installed Astro File Manager and through this I can access both root and sub-folders in Android 4.4. But I cant access the sub-folder files through Androids default file manager.

来源:https://stackoverflow.com/questions/24060059/startactivityforresult-not-working-in-android-version-4-4-kitkat-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!