5

ユーザーがSDカードから画像、オーディオ、ビデオ、docファイルを検索し、サーバーにアップロードするファイルを1つ選択できるアプリがあります。以下のコードを使用して、ギャラリーを開いて画像、オーディオ、ビデオを選択できますが、ギャラリーからドキュメントを検索する方法がわかりません。

これが私のコードです。

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);
    //intent.setType("video/*");
    //intent.setType("audio/*");
    //intent.setType("image/*");
    //**What I have to do for view document[.pdf/text/doc] file**
    startActivityForResult(Intent.createChooser(intent, "Complete action using"), REQUEST_CODE);

これを達成する方法を知っている人はいますか? どんな助けでも大歓迎です。

4

3 に答える 3

1

このライブラリaFileChooser を試してみてください

Pls はこのリンクを参照してください

于 2014-02-19T07:14:04.337 に答える
0

次のことを試してください、

File docfolder = new File(Environment.getExternalStorageDirectory() + "/"
                + "Documents/");
File docList[] = docfolder.listFiles();
for(int i=0;i<docList.length;i++)
{   
        if (docList[i].exists()) {
            Uri path = Uri.fromFile(docList[i]);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(path, "application/msword");
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            try {
                startActivity(intent);
            }
             catch (ActivityNotFoundException e) {

            }
        }
}
于 2012-05-24T17:08:54.823 に答える
0

これがドキュメントを開くのに役立つことを願っています

public void openDOC(String name) {


        File file = new File(Environment.getExternalStorageDirectory() + "/"
                + bmodel.getUserMasterBO().getUserid() + "/" + name);
        if (file.exists()) {
            Uri path = Uri.fromFile(file);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(path, "application/msword");
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            try {
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(this, "No Application Available to View DOC",
                        Toast.LENGTH_SHORT).show();
            }
        }

    }
于 2012-05-24T13:33:50.440 に答える