16

我想在我的游戏中添加一个按钮,该按钮将打开我在 Play 商店中的应用程序的 URL。以下是我到目前为止所得到的,但是当我单击速率按钮时,它不会打开相应的 URL。

我的费率代码是:

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;
    }
}
4

2 回答 2

38

你真的应该在 Net 模块中使用openURI方法。

就像是:

Gdx.net.openURI("https://play.google.com/store/apps/details?id=com.shagunstudios.racinggame");

exec可能不是跨平台的,至少不能在 Android 上运行。
不要重新发明轮子。

于 2013-07-05T14:28:18.703 回答
0

放置一个包含如下代码的方法:

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/whateveryoururlis"));
this.startActivity(i);

在您的 Android 后端(在扩展 Libgdx 的类中AndroidApplication)。然后使用接口将该方法公开给与平台无关的 Libgdx 代码(并在其他后端提供占位符实现)。有关详细信息,请参阅https://code.google.com/p/libgdx/wiki/ApplicationPlatformSpecific

于 2013-07-05T18:44:18.910 回答