コンテンツプロバイダとインテント

162 views
Skip to first unread message

hiro...@gmail.com

unread,
Jul 18, 2010, 1:10:42 AM7/18/10
to android-g...@googlegroups.com
ひいろと言います。
勉強のために、コンテンツプロバイダを使ったプログラムを
作成しようとしています。


以下のようなプログラムで、googleのトップページを表示できました。

//インテントでgoogleのトップページを表示
Intent intent =new Intent(
"android.intent.action.VIEW",
Uri.parse("http://www.google.com/"));
startActivity(intent);


また、自前でファイルを提供するコンテンツプロバイダ
(test.fileprovider)を作成し、以下のようなプログラムで
index.htmlを表示できることを確認しました。

//Webビューで表示
WebView webView=new WebView(this);
setContentView(webView);
webView.loadUrl("content://test.fileprovider/index.html");


そこで、インテントを用いてindex.htmlを表示させようと、
以下のようなプログラムを作成して実行したのですが、

//インテント
Intent intent =new Intent(
"android.intent.action.VIEW",
Uri.parse("content://test.fileprovider/index.html"));
startActivity(intent);


以下のようなエラーが出てForce closeさせられてしまいました。

The application FileProviderTest (process test.fileprovider)
has stopped unexpectedly. Please try again.

このようなインテントの使い方はできないのでしょうか?


AndroidSDKは2.2を使用し、動作環境はAndroid1.6、ApiLevel4です。
AVDのエミュレータでも実機(Xperia)でも同じ動作になりました。

hiro...@gmail.com

unread,
Jul 19, 2010, 10:26:06 AM7/19/10
to android-g...@googlegroups.com
ひいろです。

自己フォローですが、エラーが出た部分を以下のように変更するとちゃんとindex.htmlが表示されました。

Intent intent =new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("content://test.fileprovider/index.html"),
"text/html");
startActivity(intent);

ACTIONとDATAだけではなく、TYPEも指定しなければいけなかったんですね。
すみません超初心者で・・・

#TYPEが不明な場合はあきらめるんですかね。


2010年7月18日14:10 <hiro...@gmail.com>:

----
ひいろ
http://members3.jcom.home.ne.jp/hyyro/

Reply all
Reply to author
Forward
0 new messages