Reputation: 621
I want add a button in my game that will open up an URL to my app in Play Store. Below is what I got so far, but when I click on rate button it does not open the respective URL.
My rate code is:
if(Gdx.input.justTouched()){
guiCam.unproject(touchPoint.set(Gdx.input.getX(),Gdx.input.getY(), 0));
if(OverlapTester.pointInRectangle(rateButtonBound, touchPoint.x, touchPoint.y)){
try {
Process p = Runtime.getRuntime().exec("cmd /c start https://play.google.com/store/apps/details?id=com.shagunstudios.racinggame");
}
catch (IOException e1) {
System.out.println(e1);
}
if(Settings.soundEnabled)
Assets.click_sound.play(1.0f);
return;
}
}
Upvotes: 16
Views: 7968
Reputation: 4011
You should really be using openURI method in the Net module.
Something like:
Gdx.net.openURI("https://play.google.com/store/apps/details?id=com.shagunstudios.racinggame");
exec
is probably not cross platform and will not work on Android at the least.
Don't re-invent the wheel.
Upvotes: 38
Reputation: 25177
Put a method containing code like this:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/whateveryoururlis"));
this.startActivity(i);
in your Android back end (in the class that extends the Libgdx AndroidApplication
). Then expose that method to your platform independent Libgdx code using an interface (and provide place holder implementations on your other backends). See https://code.google.com/p/libgdx/wiki/ApplicationPlatformSpecific for details.
Upvotes: 1