ฉันพยายามใช้บริการ Google Play ในแอป Android ของฉัน ตามที่ Google เอกสารบอกเราต้องตรวจสอบว่า Google API พร้อมใช้งานหรือไม่ก่อนใช้งาน ฉันได้ค้นหาวิธีการตรวจสอบบางอย่างแล้ว นี่คือสิ่งที่ฉันได้รับ:
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
แต่เมื่อฉันไปที่หน้า Google Api GooglePlayServicesUtil https://developers.google.com/android/reference/com/google/android/gms/common/GooglePlayServicesUtil
ผมพบว่าการทำงานทั้งหมดจะเลิก ตัวอย่างเช่นวิธีการ
GooglePlayServicesUtil.isGooglePlayServicesAvailable (เลิกใช้แล้ว)
และ Google แนะนำให้ใช้:
GoogleApiAvailability.isGooglePlayServicesAvailable
อย่างไรก็ตามเมื่อฉันพยายามใช้ GoogleApiAvailability.isGooglePlayServicesAvailable ฉันได้รับข้อความแสดงข้อผิดพลาด:
GooglePlayServicesUtil
หายไปแล้ว (ซึ่งดูเหมือนเป็นการปฏิบัติที่ไม่ดีสำหรับการอัปเดต "เล็กน้อย") แต่ฉันไม่เห็นว่าGoogleApiAvailability
จะใช้ทดแทนได้