Migrieren Sie zum 1.0.0-beta Input SDK
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
In diesem Leitfaden wird beschrieben, wie Sie Ihr Spiel auf das neueste Input SDK umstellen. Das 1.0.0-Beta-SDK bietet erhebliche Verbesserungen gegenüber der vorherigen 0.0.4-Vorabversion. Sie sollten so schnell wie möglich aus den früheren Vorschauen migrieren. Das SDK 0.0.4 funktioniert noch bis März 2023.
Abhängigkeit aktualisieren
Löschen Sie die Bibliothek 0.0.4 aus Ihrem libs
-Verzeichnis, da sie jetzt bei Maven verfügbar ist. Suchen Sie dann in der Datei build.grade
auf Modulebene nach dieser Zeile:
implementation files('libs/inputmapping-0.0.4.aar')
Ersetzen Sie ihn durch den folgenden Code:
implementation 'com.google.android.libraries.play.games:inputmapping:1.0.0-beta'
Die ehemalige abstrakte Klasse InputMappingProvider
wurde in Version 1.0.0-beta
in eine Schnittstelle umgewandelt. Die Methode onProvideInputMap()
ist weiterhin Teil der Benutzeroberfläche.
Kotlin
Entfernen Sie ()
aus der Klassendefinition, da in InputMappingProvider
kein Konstruktor aufgerufen wird.
InputMappingProvider
-Implementierung suchen:
class MyInputMapProvider : InputMappingProvider() {
override fun onProvideInputMap(): InputMap {
TODO("Not yet implemented")
}
}
und aktualisieren Sie sie auf Folgendes:
class MyInputMapProvider : InputMappingProvider {
override fun onProvideInputMap(): InputMap {
TODO("Not yet implemented")
}
}
Java
Ersetzen Sie extends
durch implements
, um anzugeben, dass Sie eine Schnittstelle implementieren, anstatt eine Klasse zu erweitern.
Suchen Sie die Stelle, an der Sie InputMappingProvider
erweitern möchten:
public class MyInputMapProvider extends InputMappingProvider {
@NonNull
@Override
public InputMap onProvideInputMap() {
// TODO: return an InputMap
}
}
Ändern Sie es, um InputMappingProvider
zu implementieren:
public class MyInputMapProvider implements InputMappingProvider {
@NonNull
@Override
public InputMap onProvideInputMap() {
// TODO: return an InputMap
}
}
registerInputMappingProvider
und unregisterInputMappingProvider
wurden durch setInputMappingProvider
und clearInputMappingProvider
ersetzt.
Außerdem nimmt clearInputMappingProvider
kein Argument mehr an. Sie müssen also keinen Verweis auf Ihren Anbieter mehr speichern, um ihn später abzumelden.
Kotlin
Wenn Sie Ihren Kartenanbieter für Eingaben registrieren möchten, suchen Sie den Aufruf von 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)
}
Und ersetzen Sie es durch setInputMappingProvider
:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val inputMappingClient = Input.getInputMappingClient(this)
inputMappingClient.setInputMappingProvider(MyInputMapProvider())
}
Um die Eingabekarte zu löschen, suchen Sie Ihren Aufruf an unregisterInputMappingProvider
:
override fun onDestroy() {
val inputMappingClient = Input.getInputMappingClient(this)
inputMappingClient.unregisterInputMappingProvider(myInputMapProvider)
super.onDestroy()
}
Und ersetzen Sie es durch clearInputMappingprovider
:
override fun onDestroy() {
val inputMappingClient = Input.getInputMappingClient(this)
inputMappingClient.clearInputMappingProvider()
super.onDestroy()
}
Java
Wenn Sie Ihren Kartenanbieter für Eingaben registrieren möchten, suchen Sie den Aufruf von 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);
}
Ersetzen Sie es durch setInputMappingProvider
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
InputMappingClient inputMappingClient = Input.getInputMappingClient(this);
inputMappingClient.setInputMappingProvider(new MyInputMapProvider());
}
Wenn Sie den Anbieter der Eingabezuordnung löschen möchten, suchen Sie den Aufruf von unregisterInputMappingProvider
:
@Override
protected void onDestroy() {
InputMappingClient inputMappingClient = Input.getInputMappingClient(this);
inputMappingClient.unregisterInputMappingProvider(myInputMapProvider);
super.onDestroy();
}
Und ersetzen Sie es durch clearInputMappingProvider
:
@Override
protected void onDestroy() {
InputMappingClient inputMappingClient = Input.getInputMappingClient(this);
inputMappingClient.clearInputMappingProvider();
super.onDestroy();
}
Alle Inhalte und Codebeispiele auf dieser Seite unterliegen den Lizenzen wie im Abschnitt Inhaltslizenz beschrieben. Java und OpenJDK sind Marken oder eingetragene Marken von Oracle und/oder seinen Tochtergesellschaften.
Zuletzt aktualisiert: 2025-07-27 (UTC).
[null,null,["Zuletzt aktualisiert: 2025-07-27 (UTC)."],[],[],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"]]