หากต้องการเข้าถึง
API ที่ขับเคลื่อนโดยบริการ Google Play
ในแอป Android คุณต้องใช้ออบเจ็กต์ไคลเอ็นต์ API ออบเจ็กต์เหล่านี้จัดการ
การเชื่อมต่อกับบริการ Google Play, จัดคิวคำขอ และดำเนินการตามลำดับ
เมื่อมีการเชื่อมต่อ คุณสร้างไคลเอ็นต์ API ใหม่ได้ตามต้องการ
เนื่องจากสร้างได้โดยไม่เสียค่าใช้จ่าย
หากต้องการเข้าถึงบริการที่ไม่ต้องมีการให้สิทธิ์ ให้สร้างอินสแตนซ์ของออบเจ็กต์ไคลเอ็นต์ของบริการ โดยส่งผ่านContext หรือออบเจ็กต์ Activity หากจำเป็น ระบบจะแจ้งให้ผู้ใช้อัปเกรดบริการ Google Play ก่อน
ที่จะมีการเรียกใช้ API
// Code required for requesting location permissions omitted for brevity.valclient=LocationServices.getFusedLocationProviderClient(this)// Get the last known location. In some rare situations, this can be null.client.lastLocation.addOnSuccessListener{location:Location? ->
location?.let{// Logic to handle location object.}}
Java
// Code required for requesting location permissions omitted for brevity.FusedLocationProviderClientclient=LocationServices.getFusedLocationProviderClient(this);// Get the last known location. In some rare situations, this can be null.client.getLastLocation().addOnSuccessListener(this,location->{if(location!=null){// Logic to handle location object.}});
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-09-10 UTC"],[[["\u003cp\u003eTo use Google Play services APIs, create API client objects which manage the connection and queue requests when offline.\u003c/p\u003e\n"],["\u003cp\u003eAccess services without authorization by obtaining the client object using the current \u003ccode\u003eContext\u003c/code\u003e or \u003ccode\u003eActivity\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eAccess services requiring authorization by signing in the user, requesting necessary permissions, and then getting the client object.\u003c/p\u003e\n"],["\u003cp\u003eCheck for API availability using \u003ccode\u003echeckApiAvailability()\u003c/code\u003e if you need to disable features when an API is unavailable, although API calls will fail gracefully if the API isn't present.\u003c/p\u003e\n"]]],["To use Google Play services APIs, create an API client object, which manages the connection and queues requests. For services not requiring authorization, obtain the client instance using `Context` or `Activity`; for example, the Fused Location Provider client. For services requiring authorization, sign the user in, request necessary permissions, and then get the client using `GoogleSignInAccount`. For example, the Fit API client to get the daily steps. Before making API calls check with `checkApiAvailability()`.\n"],null,[]]