1

私のアプリケーションを介して、ユーザーはファイルマネージャーからファイルを選択し、選択したファイル (例: PDF ドキュメント) を処理して、印刷や電子メールなどの他の手順を実行できます。

これを行うには、以下のコードを使用してインテントを表示し、そこからユーザーがファイル マネージャー オプションからファイルを選択できるようにしました。

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);
        }
    }

Android Kitkat バージョン (4.4) の問題:

上記のコードを使用して、Android 4.3 および Android 4.4 を除くすべての Android バージョンのファイル マネージャー (つまり、サブ フォルダーとルート フォルダーの両方) からすべてのファイルにアクセスできます。

Android 4.4 では、ルート フォルダーからファイルにアクセスできますが、サブフォルダーからファイルにアクセスすることはできません。私はjava.io.FileNotFoundException例外として取得します。

注: Astro File Managerをインストールしました。これにより、Android 4.4 のルート フォルダーとサブフォルダーの両方にアクセスできます。しかし、Android のデフォルトのファイル マネージャからサブフォルダ ファイルにアクセスできません。

4

0 に答える 0