ตั้งค่าบริการ Google Play

หากต้องการพัฒนาแอปโดยใช้ API ของบริการ Google Play ให้ทำตามวิธีการในหน้านี้เพื่อตั้งค่า โปรเจ็กต์ด้วย SDK ที่เกี่ยวข้อง ซึ่งมีให้บริการจากที่เก็บ Maven ของ Google

หากต้องการทดสอบแอปเมื่อใช้บริการ Google Play คุณต้องใช้รายการใดรายการหนึ่งต่อไปนี้

  • อุปกรณ์ Android ที่เข้ากันได้ซึ่งใช้ Android 6.0 (API ระดับ 23) ขึ้นไปและมีแอป Google Play Store ติดตั้งอยู่
  • โปรแกรมจำลอง Android ที่มี AVD ซึ่งเรียกใช้แพลตฟอร์ม Google APIs ที่อิงตาม Android 6.0 (API ระดับ 23) ขึ้นไป

ประกาศทรัพยากร Dependency สำหรับบริการ Google Play

หากต้องการพัฒนาฟีเจอร์ที่ต้องใช้ API ของบริการ Google Play ในแอป ให้ทำตามขั้นตอนต่อไปนี้

  1. เปิดไฟล์ build.gradle ภายในไดเรกทอรีโมดูลของแอป

  2. สำหรับ SDK แต่ละรายการที่แอปของคุณต้องใช้ ให้รวมทรัพยากร Dependency สำหรับ SDK นั้น หน้านี้มีส่วนที่แสดงรายการการอ้างอิง บริการของ Google Play ทั่วไปสำหรับแอป Android คุณอาจต้องเพิ่ม Firebase ลงใน โปรเจ็กต์ด้วย

  3. บันทึกการเปลี่ยนแปลงและซิงค์ โปรเจ็กต์

ข้อมูลโค้ดต่อไปนี้แสดงตัวอย่างไฟล์ build.gradle ที่ใช้ไลบรารีตำแหน่ง

apply plugin: 'com.android.application'

...

dependencies {
    implementation 'com.google.android.gms:play-services-location:21.3.0'
}

เราจะเผยแพร่ SDK ของบริการ Google Play เวอร์ชันใหม่ที่มีการแก้ไขข้อบกพร่องและฟีเจอร์ใหม่ๆ เป็นระยะ เราจะประกาศการอัปเดตเหล่านี้ในบันทึก ประจำรุ่น หากแอปใช้ทรัพยากร Dependency ที่ได้รับการอัปเดต ให้เปลี่ยนเป็นเวอร์ชันล่าสุดในทรัพยากร Dependency ของแอปเพื่อใช้ประโยชน์จากการแก้ไขเหล่านี้

เพื่อรักษาคลาสที่จำเป็น

ตรวจสอบว่าได้ติดตั้งบริการ Google Play แล้วหรือไม่

ดังที่อธิบายไว้ในภาพรวมของบริการ Google Play ระบบจะอัปเดตบริการ Google Play ใน Android 6.0 (API ระดับ 23) ขึ้นไป ผ่านแอป Google Play Store โดยอัตโนมัติ อย่างไรก็ตาม อุปกรณ์ที่ไม่มี Google Play Store จะไม่มีบริการ Google Play ติดตั้งไว้ หากแอปทำงานบนอุปกรณ์ที่ไม่มีบริการ Google Play คุณควรตรวจสอบเสมอว่ามีการติดตั้งบริการ Google Play หรือไม่ก่อนที่จะพยายามใช้ Google API หรือเปิดใช้ฟีเจอร์ที่ต้องใช้บริการดังกล่าว

หากต้องการตรวจสอบว่ามีบริการ Google Play ในอุปกรณ์หรือไม่ ให้ใช้วิธี isGooglePlayServicesAvailable()

หากต้องการเริ่มเชื่อมต่อกับบริการ Google Play หรือดูวิธีตรวจหาว่าบริการ Google Play เวอร์ชันที่ติดตั้งรองรับ API ใดหรือไม่ โปรดอ่านคำแนะนำเกี่ยวกับการเข้าถึง Google API

ทรัพยากร Dependency ของบริการ Google Play

ตารางต่อไปนี้แสดงรายการการอ้างอิงสำหรับบริการ Google Play ที่คุณ รวมไว้ในแอป Android ได้ คุณสามารถกรองรายการตามประเภทอุปกรณ์ได้โดยเลือก ปุ่มใดปุ่มหนึ่ง และค้นหากรณีการใช้งานหรือชื่อการอ้างอิงที่เฉพาะเจาะจงได้ โดยป้อนข้อความลงในช่องที่ปรากฏหลังจากปุ่ม

ตารางที่ 1 การอ้างอิงบริการ Google Play ที่จะรวมไว้ใน แอป Android
กรณีการใช้งานและชื่อการขึ้นต่อกัน อุปกรณ์ที่รองรับ
โฆษณา Google บนอุปกรณ์เคลื่อนที่
com.google.android.gms:play-services-ads:24.4.0
โทรศัพท์ แท็บเล็ต
รหัสโฆษณา Android (AAID)
com.google.android.gms:play-services-ads-identifier:18.2.0
โทรศัพท์, แท็บเล็ต, Android TV, ChromeOS
Google Mobile Ads เวอร์ชันน้ำหนักเบา
com.google.android.gms:play-services-ads-lite:24.3.0
โทรศัพท์ แท็บเล็ต
โฆษณา Search ที่กำหนดเอง (CSA) ของ AdSense สำหรับ Search (AFS)
com.google.android.gms:play-services-afs-native:19.1.0
โทรศัพท์ แท็บเล็ต ChromeOS
SDK บริการ Google Analytics สำหรับ Android
com.google.android.gms:play-services-analytics:18.1.1
เลิกใช้งานแล้ว ให้ใช้ Google Analytics สำหรับ Firebase แทน
ดัชนีแอป
com.google.android.gms:play-services-appindex:16.2.0
โทรศัพท์ แท็บเล็ต Android TV
AppSearch
com.google.android.gms:play-services-appsearch:16.0.1
โทรศัพท์ แท็บเล็ต Android TV
รหัสชุดแอป Android
com.google.android.gms:play-services-appset:16.1.0
โทรศัพท์, แท็บเล็ต, Android TV, ChromeOS
Google Sign-In สำหรับ Android
com.google.android.gms:play-services-auth:21.3.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS
SMS Retriever API
com.google.android.gms:play-services-auth-api-phone:18.2.0
โทรศัพท์ แท็บเล็ต Android Go
บล็อก Store API (รวมถึงที่เก็บข้อมูลเข้าสู่ระบบของผู้ใช้)
com.google.android.gms:play-services-auth-blockstore:16.4.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
Google Awareness API
com.google.android.gms:play-services-awareness:19.1.0
โทรศัพท์, แท็บเล็ต, Auto, Android Go, ChromeOS
คลาสยูทิลิตี
com.google.android.gms:play-services-base:18.7.2
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
การทดสอบ Fake สำหรับคลาสยูทิลิตี
com.google.android.gms:play-services-base-testing:16.1.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
คลาสยูทิลิตีเพิ่มเติม
com.google.android.gms:play-services-basement:18.7.1
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
การเพิ่มประสิทธิภาพในที่แสงน้อยของกล้อง
com.google.android.gms:play-services-camera-low-light-boost:16.0.1-beta04
โทรศัพท์ แท็บเล็ต
Google Cast
com.google.android.gms:play-services-cast:22.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
เฟรมเวิร์กแอปพลิเคชัน Google Cast (CAF)
com.google.android.gms:play-services-cast-framework:22.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
Google Code Scanner
com.google.android.gms:play-services-code-scanner:16.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
สแต็กเครือข่าย Chromium (Cronet)
com.google.android.gms:play-services-cronet:18.1.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
การโต้ตอบระหว่างอุปกรณ์ (DTDI)
com.google.android.gms:play-services-dtdi:16.0.0-beta02
โทรศัพท์ แท็บเล็ต Android Go
การตรวจสอบสิทธิ์ Fast IDentity Online (FIDO)
com.google.android.gms:play-services-fido:21.2.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS

รองรับในอุปกรณ์ที่ใช้ Android 7.0 (API ระดับ 24) ขึ้นไป
Google Fit API สำหรับ Android และ Recording API บนอุปกรณ์เคลื่อนที่ (สำหรับข้อมูลการออกกำลังกายของผู้ใช้)
com.google.android.gms:play-services-fitness:21.2.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS, Wear OS
บริการเกมของ Google Play v2 สำหรับ Android
com.google.android.gms:play-services-games-v2:21.0.0
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
SDK ของบริการเกมของ Google Play เวอร์ชัน 2 สำหรับ Android ที่เขียนด้วยภาษา C
com.google.android.gms:play-services-games-v2-native-c:17.0.0-beta1
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
บริการเกมของ Google Play v1 สำหรับ Android
com.google.android.gms:play-services-games:23.2.0
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
Matter API
com.google.android.gms:play-services-home:16.0.0
โทรศัพท์ แท็บเล็ต
Google Play Instant
com.google.android.gms:play-services-instantapps:18.2.0
เลิกใช้งานแล้ว ดูข้อมูลเพิ่มเติมได้ที่ Google Play Instant
บริการตำแหน่งสำหรับ Android
com.google.android.gms:play-services-location:21.3.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
Google Maps SDK สำหรับ Android
com.google.android.gms:play-services-maps:19.2.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
Google Maps 3D SDK สำหรับ Android
com.google.android.gms:play-services-maps3d:0.0.2
โทรศัพท์ แท็บเล็ต
การสแกนบาร์โค้ดด้วย ML Kit
com.google.android.gms:play-services-mlkit-barcode-scanning:18.3.1
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
เครื่องสแกนเอกสาร ML Kit
com.google.android.gms:play-services-mlkit-document-scanner:16.0.0-beta1
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การตรวจจับใบหน้าของ ML Kit
com.google.android.gms:play-services-mlkit-face-detection:17.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การติดป้ายกำกับรูปภาพด้วย ML Kit
com.google.android.gms:play-services-mlkit-image-labeling:16.0.8
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การติดป้ายกำกับรูปภาพที่กำหนดเองของ ML Kit
com.google.android.gms:play-services-mlkit-image-labeling-custom:16.0.0-beta5
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การระบุภาษาของ ML Kit
com.google.android.gms:play-services-mlkit-language-id:17.0.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
ฟีเจอร์ช่วยตอบของ ML Kit
com.google.android.gms:play-services-mlkit-smart-reply:16.0.0-beta1
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การแบ่งกลุ่มวัตถุด้วย ML Kit
com.google.android.gms:play-services-mlkit-subject-segmentation:16.0.0-beta1
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจำข้อความของ ML Kit
com.google.android.gms:play-services-mlkit-text-recognition:19.0.1
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจำข้อความของ ML Kit สำหรับภาษาจีน
com.google.android.gms:play-services-mlkit-text-recognition-chinese:16.0.1
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจำข้อความของ ML Kit สำหรับเทวนาครี
com.google.android.gms:play-services-mlkit-text-recognition-devanagari:16.0.1
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจำข้อความภาษาญี่ปุ่นของ ML Kit
com.google.android.gms:play-services-mlkit-text-recognition-japanese:16.0.1
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจำข้อความของ ML Kit สำหรับภาษาเกาหลี
com.google.android.gms:play-services-mlkit-text-recognition-korean:16.0.1
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การค้นหาและการเชื่อมต่ออุปกรณ์ที่อยู่ใกล้เคียง
com.google.android.gms:play-services-nearby:19.3.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go
แสดงใบอนุญาตโอเพนซอร์ส
com.google.android.gms:play-services-oss-licenses:17.2.1
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS
รองรับในอุปกรณ์ที่ใช้ Android 5.0 (API ระดับ 21) ขึ้นไป
ไลบรารีการเข้าถึงแบบเป็นโปรแกรม (PAL)
com.google.android.gms:play-services-pal:22.0.0
โทรศัพท์ แท็บเล็ต Android TV
รองรับในอุปกรณ์ที่ใช้ Android 5.0 (API ระดับ 21) ขึ้นไป
ตรวจสอบคุณภาพการล็อกหน้าจอ
com.google.android.gms:play-services-password-complexity:18.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS, Wear OS

รองรับในอุปกรณ์ที่ใช้ Android 4.4 (API ระดับ 19) ถึง Android 9 (API ระดับ 28)
Google Wallet (เดิมคือ Google Pay สำหรับบัตร)
com.google.android.gms:play-services-pay:16.5.0
โทรศัพท์ แท็บเล็ต Android Go, ChromeOS

รองรับในอุปกรณ์ที่ใช้ Android 5.0 (API ระดับ 20) ขึ้นไป
reCAPTCHA Enterprise สำหรับการวัดผลแอป
com.google.android.gms:play-services-recaptcha:17.1.0
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
SafetyNet API (รวมถึงการท่องเว็บอย่างปลอดภัยและการยืนยันแอป)
com.google.android.gms:play-services-safetynet:18.1.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS
Google Tag Manager
com.google.android.gms:play-services-tagmanager:18.3.0
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
Tasks API ใน Android
com.google.android.gms:play-services-tasks:18.3.2
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
บริการเร่งความเร็วสำหรับ Android
com.google.android.gms:play-services-tflite-acceleration-service:16.4.0-beta01
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
TensorFlow Lite GPU Delegate API สำหรับบริการ Google Play
com.google.android.gms:play-services-tflite-gpu:16.4.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
TensorFlow Lite Java API สำหรับบริการ Google Play
com.google.android.gms:play-services-tflite-java:16.4.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
TensorFlow Lite Support API สำหรับบริการ Google Play
com.google.android.gms:play-services-tflite-support:16.4.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
Thread Network API
com.google.android.gms:play-services-threadnetwork:16.3.0
โทรศัพท์ แท็บเล็ต
Trusted Time API
com.google.android.gms:play-services-time:16.0.1
โทรศัพท์, แท็บเล็ต, Auto, Android Go, Wear OS
Mobile Vision
com.google.android.gms:play-services-vision:20.1.3
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
Google Pay สำหรับการชำระเงินใน Android
com.google.android.gms:play-services-wallet:19.4.0
โทรศัพท์, แท็บเล็ต, Auto, Android Go, ChromeOS, Wear OS
Wearable Data Layer API
com.google.android.gms:play-services-wearable:19.0.0
โทรศัพท์ แท็บเล็ต Wear OS

ปลั๊กอิน Gradle

นอกจากนี้ บริการ Google Play ยังมีปลั๊กอิน Gradle หลายรายการดังที่แสดงในตารางต่อไปนี้ โปรดทราบว่าปุ่มที่ปรากฏก่อนตารางก่อนหน้า จะไม่เปลี่ยนแปลงข้อมูลที่ปรากฏในตารางนี้

ตารางที่ 2 รายการปลั๊กอิน Gradle ที่รวมอยู่ในบริการ Google Play
กรณีการใช้งานและชื่อปลั๊กอิน Gradle อุปกรณ์ที่รองรับ
แสดงใบอนุญาตโอเพนซอร์ส
com.google.android.gms:oss-licenses-plugin:0.10.6
โทรศัพท์ แท็บเล็ต ChromeOS
การตรวจสอบเวอร์ชันอย่างเข้มงวด
com.google.android.gms:strict-version-matcher-plugin:1.2.4
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS