[JAVA] [Android] How to check if the Google Play developer service is installed when the app is launched

Event

In a certain project, I found that the following error occurred while using an in-house test terminal.

error


Failed to load googlecertificates. qw:No acceptable module found. Local version is 0 and

Correspondence

There was no error on my terminal, and when I investigated it, Apparently, the Google Play developer service is not installed on the test terminal side, so It seems that com.google.android.gms: play-services cannot be used. However, it is hard to notice because it does not end abnormally, only the error is spit out on the console. So, shouldn't it be checked at startup? </ B> Upon further investigation, it was found that the following checks are possible.

MainActivity.kt


override fun onCreate(savedInstanceState: Bundle?) {
	super.onCreate(null)

	setContentView(R.layout.activity_main)

	//Check if Google Play Developer Services is installed
	val api = GoogleApiAvailability.getInstance()
	val code = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this)
	if (code == ConnectionResult.SUCCESS) {
		//Since it has been installed, normal processing is executed.
	} else {
		//Display dialog because it is not installed
		api.getErrorDialog(this, code, 0).show()
	}

}

If it is not installed, you can call the officially prepared dialog below. api.getErrorDialog(this, code, 0).show()

Remarks

I happened to find it this time, so I responded, Basically, the Google Play developer service is should </ b> installed, so I thought it would be nice to write it at startup to the extent that it is not magical. (It's a hassle to make inquiries ...)

I didn't have a similar article on Qiita, so I wrote it as a memo for myself. I hope it will be helpful for those who are having trouble with other similar matters.

Recommended Posts