在libgdx游戏中添加“评价我的应用”按钮

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;
    }
}
2个回答

38

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

类似这样:

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

exec 可能不是跨平台的,在 Android 上至少无法使用。
不要重复造轮子。


想提供更多细节吗? - XiaoChuan Yu
现在它正在工作,我不知道以前为什么总是崩溃。 - Boldijar Paul
5
您可能忘记在 Android Manifest 文件中提供互联网访问权限。 - Diljeet
Gdx.net.openURI 对我来说运行非常缓慢。一旦我点击按钮,它会在 3 秒后跳转到 Playstore,在这 3 秒的时间内什么也不会发生,用户会感到怀疑,然后一旦跳转到 Playstore,Playstore 似乎也要进行许多计算,因为 Playstore 也变得非常缓慢。我看到一个白屏持续了 3 秒,然后我的游戏页面才出现。有什么想法吗? - Sagar Balyan
@SagarBalyan 设备很慢吗?该函数的实现非常简单。我猜你在使用Android系统。 请参考源代码: https://github.com/libgdx/libgdx/blob/master/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidNet.java - XiaoChuan Yu

1

编写一个包含以下代码的方法:

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

在扩展了Libgdx AndroidApplication的类中,编写你的Android后端代码。然后使用接口将该方法暴露给平台无关的Libgdx代码(并在其他后端提供占位符实现)。详情请参见https://code.google.com/p/libgdx/wiki/ApplicationPlatformSpecific


2
或者,您可以调用openURI,如果您查看source,它实际上在Android后端实现中执行相同的操作。 - XiaoChuan Yu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接