Migrate to the 1.0.0-beta Input SDK
Stay organized with collections
Save and categorize content based on your preferences.
This guide describes how to migrate your game to use the latest Input SDK. The 1.0.0-beta SDK has substantial improvements over the previous 0.0.4 preview. You should migrate from the earlier previews as soon as possible. The 0.0.4 SDK will continue function through March 2023.
Update the dependency
Delete the 0.0.4 library from your libs directory since the library is now
available on maven. Then Find this line in your module-level build.grade
file:
implementationfiles('libs/inputmapping-0.0.4.aar')
Replace it with the following code:
implementation'com.google.android.libraries.play.games:inputmapping:1.0.0-beta'
Implement the new InputMappingProvider interface
The former abstract class InputMappingProvider turned into an interface in
version 1.0.0-beta. The method onProvideInputMap() is still part of the
interface.
Kotlin
Remove () from the class definition since there's no constructor to invoke in
InputMappingProvider.
Locate your InputMappingProvider implementation:
classMyInputMapProvider:InputMappingProvider(){
overridefunonProvideInputMap():InputMap{
TODO("Not yet implemented")
}
}
And update it to this:
classMyInputMapProvider:InputMappingProvider{
overridefunonProvideInputMap():InputMap{
TODO("Not yet implemented")
}
}
Java
Replace extends with implements to indicate that your implementing an
interface rather than extending a class.
Locate where you extend InputMappingProvider:
publicclass MyInputMapProviderextendsInputMappingProvider{
@NonNull
@Override
publicInputMaponProvideInputMap(){
// TODO: return an InputMap
}
}
And change it to implement InputMappingProvider:
publicclass MyInputMapProviderimplementsInputMappingProvider{
@NonNull
@Override
publicInputMaponProvideInputMap(){
// TODO: return an InputMap
}
}
Use the new InputClient
registerInputMappingProvider and unregisterInputMappingProvider have been
replaced with setInputMappingProvider and clearInputMappingProvider.
Further, clearInputMappingProvider no longer takes an argument so you no
longer need to keep a reference to your provider to unregister it later.
Kotlin
To register your input map provider, locate your call toregisterInputMappingProvider:
privatevalmyInputMapProviderbylazy{
MyInputMapProvider()
}
overridefunonCreate(savedInstanceState:Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
valinputMappingClient=Input.getInputMappingClient(this)
inputMappingClient.registerInputMappingProvider(myInputMapProvider)
}
And replace it with setInputMappingProvider:
overridefunonCreate(savedInstanceState:Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
valinputMappingClient=Input.getInputMappingClient(this)
inputMappingClient.setInputMappingProvider(MyInputMapProvider())
}
To clear your input map, locate your call to unregisterInputMappingProvider:
overridefunonDestroy(){
valinputMappingClient=Input.getInputMappingClient(this)
inputMappingClient.unregisterInputMappingProvider(myInputMapProvider)
super.onDestroy()
}
And replace it with clearInputMappingprovider:
overridefunonDestroy(){
valinputMappingClient=Input.getInputMappingClient(this)
inputMappingClient.clearInputMappingProvider()
super.onDestroy()
}
Java
To register your input map provider, locate your call to
registerInputMappingProvider:
privatefinalMyInputMapProvidermyInputMapProvider=newMyInputMapProvider();
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
InputMappingClientinputMappingClient=Input.getInputMappingClient(this);
inputMappingClient.registerInputMappingProvider(myInputMapProvider);
}
And replace it with setInputMappingProvider:
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
InputMappingClientinputMappingClient=Input.getInputMappingClient(this);
inputMappingClient.setInputMappingProvider(newMyInputMapProvider());
}
To clear your input mapping provider, locate your call to
unregisterInputMappingProvider:
@Override
protectedvoidonDestroy(){
InputMappingClientinputMappingClient=Input.getInputMappingClient(this);
inputMappingClient.unregisterInputMappingProvider(myInputMapProvider);
super.onDestroy();
}
And replace it with clearInputMappingProvider:
@Override
protectedvoidonDestroy(){
InputMappingClientinputMappingClient=Input.getInputMappingClient(this);
inputMappingClient.clearInputMappingProvider();
super.onDestroy();
}