开发者

open a url on click intent [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 8 years ago.

开发者_开发问答 Improve this question

I can't find a way to make this code work, please help.

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
@SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);                   
Toast.makeText(Main.this, "ID '" + o.get("id")+"' url '"+ o.get("url") + "' was clicked.", Toast.LENGTH_LONG).show();           

Intent browserIntent = new Intent("android.intent.action.VIEW",Uri.parse(o.get("url")));
            startActivity(browserIntent);

        }


Try the following code:

Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://stackoverflow.com/"));
startActivity(myIntent);


open URL in WebView

public void openNewActivity(View view) { 
Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
mWebView.loadUrl("http://google.com");

}

open URL in Default Browser

public void openNewActivity(View view) { 
Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse("http://google.com"));
startActivity(myWebLink);
 }


Your code is wrong, it should be:

Intent browserIntent = new Intent(android.intent.action.VIEW,Uri.parse(o.get("url"))); 
startActivity(browserIntent);

And yes don't forget to add INTERNET Permission in the AndroidManifest.xml file.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜