This code snippet helps you to open browser in android cocos2D application

public void openBrowser(){
		CCDirector.sharedDirector().getActivity().runOnUiThread(new Runnable() {
		    public void run() {
				Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
				CCDirector.sharedDirector().getActivity().startActivity(browserIntent);
		}});
	}

Call this function anywhere inside your cocos2D project to open the browser with the corresponding URL.

 

2 Comments

  1. David May 11, 2012 at 3:09 pm

    Excuse me, I implemented this, but I would like to know how can I do it so that when I press the phone’s back button it goes back to the cocos2d layer that called the openBrowser method, when I press it, it restarts the game from the beginning

     
    • James May 12, 2012 at 1:03 am

      IF you have opened the browser from a cocos2DLayer then clicking on back button will bring you back to the previous cocos2d layer. Please check if you are not destroying the activity then the onPause() function is called on the activity when your browser is opened, this may be causing the game to restart.

       

Leave a Reply

Your email address will not be published. Required fields are marked *

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.