user2846367
user2846367

Reputation: 25

How to add a website link in android through touch button

I have written this android code but its not working or showing anything when clicked. I have no XML activity in this code for this.

public Pro(Game game) {
    super(game);
}

@Override
public void update(float deltaTime) {
    Graphics g = game.getGraphics();
    List<TouchEvent> touchEvents = game.getInput().getTouchEvents();

    int len1 = touchEvents.size();
    for (int i = 0; i < len1; i++) {
        TouchEvent event = touchEvents.get(i);
        if (event.type == TouchEvent.TOUCH_UP) {

            if (inBounds(event, 550, 350, 350, 450)) {
                try {
                    URI uri = new URI("www.google.com");
                } catch (URISyntaxException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}

private boolean inBounds(TouchEvent event, int x, int y, int width,
        int height) {
    if (event.x > x && event.x < x + width - 1 && event.y > y
            && event.y < y + height - 1)
        return true;
    else
        return false;
}

Please help me to solve the problem.

Upvotes: 1

Views: 765

Answers (2)

hardik pansuria
hardik pansuria

Reputation: 208

URI uri = new URI("www.google.com"); This doesn't work at all .

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

Upvotes: 0

A.S.
A.S.

Reputation: 4574

if you want to open a Browser with this URL just follow the answers of this question Sending an Intent to browser to open specific URL

Upvotes: 1

Related Questions