从应用程序启动Web浏览器

时间:2011-07-14 22:35:27

标签: android browser

我正在尝试从具有特定网址的应用程序对话框中打开Android中的默认浏览器。我使用个人对话框类,使用公共方法插入可引发文本:

public class PictureInfoView extends Dialog {
private Context mContext;

public PictureInfoView(Context context) {
    super(context);
    mContext = context;
    ....
}
public void addSource(final String newSource) {
    TextView t = new TextView(mContext);
    t.setClickable(true);
    t.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            dismiss();
            try{
            Intent viewIntent = new Intent("Intent.ACTION_VIEW",
                    Uri.parse( "http://www.google.com" ));
            mContext.startActivity(viewIntent);
            }catch(Exception e){
                Log.e("CC", "PictureInfoView: " + e.getMessage());
            }
        }
    });
    v.addView(t, 0);
}
...
}

但是当点击文本时,会有一条例外情况:

"No activity found to handle Intent { act=Intent.ACTION_VIEW dat=http://www.google.com }"

问题出在哪里?

谢谢大家! =)

2 个答案:

答案 0 :(得分:2)

Intent viewIntent = new Intent("Intent.ACTION_VIEW",
                Uri.parse( "http://www.google.com" ));

应该看起来像

Intent viewIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse( "http://www.google.com" ));

或者使用“android.intent.action.VIEW”(那是来自Intent.ACTION_VIEW的字符串,see here

答案 1 :(得分:0)

有可能,你的清单中没有包含uses-permission android:name =“android.permission.INTERNET”吗?