开发者

Launch web browser from application

开发者 https://www.devze.com 2023-03-20 05:34 出处:网络
I\'m trying to open default browser in Android from an application\'s dialog with a sp开发者_运维技巧ecific url. I use a personal dialog class, with a public method to insert clickeable text:

I'm trying to open default browser in Android from an application's dialog with a sp开发者_运维技巧ecific url. I use a personal dialog class, with a public method to insert clickeable text:

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

But when the text is clicked, an exception is gerenerated with this message:

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

Where is the problem?

Thanks for all! =)


This

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

should look like

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

Or use "android.intent.action.VIEW" (thats the String from Intent.ACTION_VIEW, see here)


By chance, have you not included uses-permission android:name="android.permission.INTERNET" in your manifest?

0

精彩评论

暂无评论...
验证码 换一张
取 消