遷移至 1.0.0 Beta Input SDK
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本指南會說明如何遷移遊戲,改用最新版的 Input SDK。與先前的 0.0.4 預先發布版相較,1.0.0-beta SDK 有重大的功能改進。您應盡快從先前的預先發布版遷移至新版。0.0.4 SDK 已於 2023 年 3 月失效。
更新依附元件
由於 Maven 現已提供程式庫,請從 libs
目錄中刪除 0.0.4 程式庫。接著,在模組層級的 build.grade
檔案中找出以下這一行:
implementation files('libs/inputmapping-0.0.4.aar')
替換成以下程式碼:
implementation 'com.google.android.libraries.play.games:inputmapping:1.0.0-beta'
在 1.0.0-beta
版本中,先前的抽象類別 InputMappingProvider
已轉變為介面,此介面仍會提供 onProvideInputMap()
方法。
Kotlin
從類別定義中移除 ()
,因為 InputMappingProvider
內沒有可供叫用的建構函式。
找出 InputMappingProvider
實作內容:
class MyInputMapProvider : InputMappingProvider() {
override fun onProvideInputMap(): InputMap {
TODO("Not yet implemented")
}
}
並更新為以下程式碼:
class MyInputMapProvider : InputMappingProvider {
override fun onProvideInputMap(): InputMap {
TODO("Not yet implemented")
}
}
Java
將 extends
替換為 implements
,表示要實作介面,並非要擴充類別。
找出擴充 InputMappingProvider
的位置:
public class MyInputMapProvider extends InputMappingProvider {
@NonNull
@Override
public InputMap onProvideInputMap() {
// TODO: return an InputMap
}
}
並改為實作 InputMappingProvider
:
public class MyInputMapProvider implements InputMappingProvider {
@NonNull
@Override
public InputMap onProvideInputMap() {
// TODO: return an InputMap
}
}
registerInputMappingProvider
和 unregisterInputMappingProvider
已替換為 setInputMappingProvider
和 clearInputMappingProvider
。此外,clearInputMappingProvider
已不再接受引數,因此您不必保留指向提供者的參照,用於日後取消註冊。
Kotlin
如要註冊輸入對應提供者,請找出對 registerInputMappingProvider
的呼叫:
private val myInputMapProvider by lazy {
MyInputMapProvider()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val inputMappingClient = Input.getInputMappingClient(this)
inputMappingClient.registerInputMappingProvider(myInputMapProvider)
}
並替換為 setInputMappingProvider
:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val inputMappingClient = Input.getInputMappingClient(this)
inputMappingClient.setInputMappingProvider(MyInputMapProvider())
}
如要清除輸入對應,請找出對 unregisterInputMappingProvider
的呼叫:
override fun onDestroy() {
val inputMappingClient = Input.getInputMappingClient(this)
inputMappingClient.unregisterInputMappingProvider(myInputMapProvider)
super.onDestroy()
}
並替換為 clearInputMappingprovider
:
override fun onDestroy() {
val inputMappingClient = Input.getInputMappingClient(this)
inputMappingClient.clearInputMappingProvider()
super.onDestroy()
}
Java
如要註冊輸入對應提供者,請找出對 registerInputMappingProvider
的呼叫:
private final MyInputMapProvider myInputMapProvider = new MyInputMapProvider();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
InputMappingClient inputMappingClient = Input.getInputMappingClient(this);
inputMappingClient.registerInputMappingProvider(myInputMapProvider);
}
並替換為 setInputMappingProvider
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
InputMappingClient inputMappingClient = Input.getInputMappingClient(this);
inputMappingClient.setInputMappingProvider(new MyInputMapProvider());
}
如要清除輸入對應提供者,請找出對 unregisterInputMappingProvider
的呼叫:
@Override
protected void onDestroy() {
InputMappingClient inputMappingClient = Input.getInputMappingClient(this);
inputMappingClient.unregisterInputMappingProvider(myInputMapProvider);
super.onDestroy();
}
並替換為 clearInputMappingProvider
:
@Override
protected void onDestroy() {
InputMappingClient inputMappingClient = Input.getInputMappingClient(this);
inputMappingClient.clearInputMappingProvider();
super.onDestroy();
}
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Migrate to the 1.0.0-beta Input SDK\n\nThis guide describes how to migrate your game to use the latest\nInput SDK. The 1.0.0-beta SDK has substantial improvements over the\nprevious 0.0.4 preview. You should migrate from the earlier previews as soon as\npossible. The 0.0.4 SDK will continue function through March 2023.\n\nUpdate the dependency\n---------------------\n\nDelete the 0.0.4 library from your `libs` directory since the library is now\navailable on maven. Then Find this line in your module-level `build.grade`\nfile: \n\n implementation files('libs/inputmapping-0.0.4.aar')\n\nReplace it with the following code: \n\n implementation 'com.google.android.libraries.play.games:inputmapping:1.0.0-beta'\n\nImplement the new InputMappingProvider interface\n------------------------------------------------\n\nThe former abstract class `InputMappingProvider` turned into an interface in\nversion `1.0.0-beta`. The method `onProvideInputMap()` is still part of the\ninterface.\n\n\u003cbr /\u003e\n\n### Kotlin\n\n\u003cbr /\u003e\n\nRemove `()` from the class definition since there's no constructor to invoke in\n`InputMappingProvider`.\n\nLocate your `InputMappingProvider` implementation: \n\n class MyInputMapProvider : InputMappingProvider() {\n override fun onProvideInputMap(): InputMap {\n TODO(\"Not yet implemented\")\n }\n }\n\nAnd update it to this: \n\n class MyInputMapProvider : InputMappingProvider {\n override fun onProvideInputMap(): InputMap {\n TODO(\"Not yet implemented\")\n }\n }\n\n\u003cbr /\u003e\n\n### Java\n\n\u003cbr /\u003e\n\nReplace `extends` with `implements` to indicate that your implementing an\ninterface rather than extending a class.\n\nLocate where you extend `InputMappingProvider`: \n\n public class MyInputMapProvider extends InputMappingProvider {\n @NonNull\n @Override\n public InputMap onProvideInputMap() {\n // TODO: return an InputMap\n }\n }\n\nAnd change it to implement `InputMappingProvider`: \n\n public class MyInputMapProvider implements InputMappingProvider {\n @NonNull\n @Override\n public InputMap onProvideInputMap() {\n // TODO: return an InputMap\n }\n }\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nUse the new InputClient\n-----------------------\n\n`registerInputMappingProvider` and `unregisterInputMappingProvider` have been\nreplaced with `setInputMappingProvider` and `clearInputMappingProvider`.\nFurther, `clearInputMappingProvider` no longer takes an argument so you no\nlonger need to keep a reference to your provider to unregister it later.\n\n\u003cbr /\u003e\n\n### Kotlin\n\nTo register your input map provider, locate your call to `registerInputMappingProvider`:\n\n\u003cbr /\u003e\n\n private val myInputMapProvider by lazy {\n MyInputMapProvider()\n }\n\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n setContentView(R.layout.activity_main)\n\n val inputMappingClient = Input.getInputMappingClient(this)\n inputMappingClient.registerInputMappingProvider(myInputMapProvider)\n }\n\nAnd replace it with `setInputMappingProvider`: \n\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n setContentView(R.layout.activity_main)\n\n val inputMappingClient = Input.getInputMappingClient(this)\n inputMappingClient.setInputMappingProvider(MyInputMapProvider())\n }\n\nTo clear your input map, locate your call to `unregisterInputMappingProvider`: \n\n override fun onDestroy() {\n val inputMappingClient = Input.getInputMappingClient(this)\n inputMappingClient.unregisterInputMappingProvider(myInputMapProvider)\n\n super.onDestroy()\n }\n\nAnd replace it with `clearInputMappingprovider`: \n\n override fun onDestroy() {\n val inputMappingClient = Input.getInputMappingClient(this)\n inputMappingClient.clearInputMappingProvider()\n\n super.onDestroy()\n }\n\n\u003cbr /\u003e\n\n### Java\n\n\u003cbr /\u003e\n\nTo register your input map provider, locate your call to\n`registerInputMappingProvider`: \n\n private final MyInputMapProvider myInputMapProvider = new MyInputMapProvider();\n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n\n InputMappingClient inputMappingClient = Input.getInputMappingClient(this);\n inputMappingClient.registerInputMappingProvider(myInputMapProvider);\n }\n\nAnd replace it with `setInputMappingProvider`: \n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n\n InputMappingClient inputMappingClient = Input.getInputMappingClient(this);\n inputMappingClient.setInputMappingProvider(new MyInputMapProvider());\n }\n\nTo clear your input mapping provider, locate your call to\n`unregisterInputMappingProvider`: \n\n @Override\n protected void onDestroy() {\n InputMappingClient inputMappingClient = Input.getInputMappingClient(this);\n inputMappingClient.unregisterInputMappingProvider(myInputMapProvider);\n\n super.onDestroy();\n }\n\nAnd replace it with `clearInputMappingProvider`: \n\n @Override\n protected void onDestroy() {\n InputMappingClient inputMappingClient = Input.getInputMappingClient(this);\n inputMappingClient.clearInputMappingProvider();\n\n super.onDestroy();\n }\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]