0

.doc .pdf .excel... のようなファイルがあり、それらを外部で開きたいです。

私はintent.ACTION_VIEWを試しましたが、ブラウザで開きます。

ユーザーがデフォルトのハンドラーとして持っているアプリケーションでそれらを開くにはどうすればよいですか?

File file = new File(Globals.SAVE_PATH + filename);
openFile(file.toURI());


public void openFile(URI uri) {
        Intent i = new Intent(?????);
        i.setData(Uri.parse(uri.toString()));
        startActivity(i);
    }
4

2 に答える 2

1

この記事は役に立つかもしれません。覚えておく必要があるのは、電話にファイルを開くことができるアプリが 1 つしかない場合、そのアプリは自動的に起動するということです。

于 2012-06-09T18:07:25.257 に答える
0

ご回答ありがとうございますが、この方法が最も簡単であることがわかりました。

String path="File Path";

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(path);

MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext=file.getName().substring(file.getName().lastIndexOf(".")+1);
String type = mime.getMimeTypeFromExtension(ext);

intent.setDataAndType(Uri.fromFile(file),type);

startActivity(intent);
于 2012-06-09T20:21:48.633 に答える