2013-07-05 29 views
14

我想在我的遊戲中添加一個按鈕,該按鈕將在Play商店中打開我的應用的網址。下面是我到目前爲止,但是當我點擊率按鈕,它不會打開相應的網址。在libgdx遊戲中添加「評價我的應用」按鈕

我率的代碼是:

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

回答

37

你真正應該使用網絡模塊openURI方法。

喜歡的東西:

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

exec可能不是跨平臺,並在至少在Android上是行不通的。
不要重新發明車輪。

+0

不適用於機器人或臺式機 –

+0

想要提供更多詳細信息? –

+0

嗯,現在是工作,我不知道爲什麼我用得到崩潰 –

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

+2

或者,你可以調用[openURI](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Net.html#openURI(java.lang.String中)) 實際上確實Android中後端實現相同的事如果你看[源代碼](https://github.com/libgdx/libgdx/blob/master/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidNet.java)。 –

相關問題