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

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

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

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

ประกาศการพึ่งพาบริการ Google Play

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

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

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

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

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

apply plugin: 'com.android.application'

...

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

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

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

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

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

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

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

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

ตารางที่ 1 ทรัพยากร Dependency ของบริการ Google Play ที่จะรวมอยู่ใน แอป Android
กรณีการใช้งานและชื่อการอ้างอิง อุปกรณ์ที่รองรับ
โฆษณาบนอุปกรณ์เคลื่อนที่ของ Google
com.google.android.gms:play-services-ads:22.1.0
โทรศัพท์ แท็บเล็ต
รหัสโฆษณา Android (AAID)
com.google.android.gms:play-services-ads-identifier:18.0.1
โทรศัพท์, แท็บเล็ต, Android TV, ChromeOS
โฆษณาบนอุปกรณ์เคลื่อนที่ของ Google ในเวอร์ชันที่เรียบง่าย
com.google.android.gms:play-services-ads-lite:22.1.0
โทรศัพท์ แท็บเล็ต
โฆษณาที่กําหนดเองในเครือข่ายการค้นหาของ AdSense (AFS)
com.google.android.gms:play-services-afs-native:19.0.3
โทรศัพท์, แท็บเล็ต, ChromeOS
SDK บริการ Google Analytics สําหรับ Android
com.google.android.gms:play-services-analytics:18.0.2
เลิกใช้งานแล้ว โปรดใช้ Google Analytics สําหรับ Firebase แทน
ดัชนีแอป
com.google.android.gms:play-services-appindex:16.1.0
โทรศัพท์, แท็บเล็ต, Android TV
รหัสชุดแอป Android
com.google.android.gms:play-services-appset:16.0.2
โทรศัพท์, แท็บเล็ต, Android TV, ChromeOS
Google Sign-In สําหรับ Android
com.google.android.gms:play-services-auth:20.5.0
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS
SMS Fetcher API
com.google.android.gms:play-services-auth-api-phone:18.0.1
โทรศัพท์, แท็บเล็ต, Android Go
Block Store API (รวมพื้นที่เก็บข้อมูลเข้าสู่ระบบของผู้ใช้)
com.google.android.gms:play-services-auth-blockstore:16.2.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
Google Awareness API
com.google.android.gms:play-services-awareness:19.0.1
โทรศัพท์, แท็บเล็ต, อัตโนมัติ, Android Go, ChromeOS
ชั้นเรียนสาธารณูปโภค
com.google.android.gms:play-services-base:18.2.0
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS, Wear OS
การทดสอบการปลอมแปลงสําหรับคลาสของยูทิลิตี
com.google.android.gms:play-services-base-testing:16.0.0
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS, Wear OS
คลาสยูทิลิตีเพิ่มเติม
com.google.android.gms:play-services-basement:18.2.0
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS, Wear OS
Google Cast
com.google.android.gms:play-services-cast:21.3.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
เฟรมเวิร์กแอปพลิเคชัน Google Cast (CAF)
com.google.android.gms:play-services-cast-framework:21.3.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
ตัวรับสัญญาณ Android TV
com.google.android.gms:play-services-cast-tv:21.0.0
Android TV
Google Code Scanner
com.google.android.gms:play-services-code-scanner:16.0.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
กลุ่มเครือข่าย Chromium (Cronet)
com.google.android.gms:play-services-cronet:18.0.1
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS, Wear OS
การโต้ตอบระหว่างอุปกรณ์ (DTDI)
com.google.android.gms:play-services-dtdi:16.0.0-beta01
โทรศัพท์, แท็บเล็ต, Android Go
การตรวจสอบสิทธิ์ Fast IDentity ออนไลน์ (FIDO)
com.google.android.gms:play-services-fido:20.0.1
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS, Wear OS

รองรับในอุปกรณ์ที่ใช้ Android 7.0 (API ระดับ 24) ขึ้นไป
Google Fit API สําหรับ Android
com.google.android.gms:play-services-fitness:21.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS, Wear OS
บริการเกมของ Google Play เวอร์ชัน 2 สําหรับ Android
com.google.android.gms:play-services-games-v2:17.0.0
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
Google Play Games Services v2 Native C SDK สําหรับ Android
com.google.android.gms:play-services-games-v2-native-c:17.0.0-beta1
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
บริการเกมของ Google Play เวอร์ชัน 1 สําหรับ Android
com.google.android.gms:play-services-games:23.1.0
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
API กรณี
com.google.android.gms:play-services-home:16.0.0
โทรศัพท์ แท็บเล็ต
Google Play Instant
com.google.android.gms:play-services-instantapps:18.0.1
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS

รองรับอุปกรณ์ที่ใช้ Android 5.0 (API ระดับ 21) ขึ้นไป
ผู้ให้บริการ Fused Location สําหรับ Android (รวมถึงการจดจํากิจกรรมและการกําหนดเขตพื้นที่เสมือน)
com.google.android.gms:play-services-location:21.0.1
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS, Wear OS
Google Maps SDK สําหรับ Android
com.google.android.gms:play-services-maps:18.1.0
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS, Wear OS
การสแกนบาร์โค้ด ML Kit
com.google.android.gms:play-services-mlkit-barcode-scanning:18.2.0
โทรศัพท์, แท็บเล็ต, 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-beta4
โทรศัพท์, แท็บเล็ต, 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-text-recognition:19.0.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจําข้อความ ML Kit สําหรับภาษาจีน
com.google.android.gms:play-services-mlkit-text-recognition-chinese:16.0.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจําข้อความ ML Kit สําหรับเทวนาครี
com.google.android.gms:play-services-mlkit-text-recognition-devanagari:16.0.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจําข้อความ ML Kit สําหรับภาษาญี่ปุ่น
com.google.android.gms:play-services-mlkit-text-recognition-japanese:16.0.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจําข้อความ ML Kit สําหรับเกาหลี
com.google.android.gms:play-services-mlkit-text-recognition-korean:16.0.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การค้นพบและการเชื่อมต่อกับอุปกรณ์ที่อยู่ใกล้เคียง
com.google.android.gms:play-services-nearby:18.5.0
โทรศัพท์, แท็บเล็ต, Android TV, รถยนต์, Android Go
แสดงใบอนุญาตโอเพนซอร์ส
com.google.android.gms:play-services-oss-licenses:17.0.1
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS
รองรับในอุปกรณ์ที่ใช้ Android 5.0 (API ระดับ 21) ขึ้นไป
การตรวจสอบคุณภาพของการล็อกหน้าจอ
com.google.android.gms:play-services-password-complexity:18.0.1
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS, Wear OS

รองรับในอุปกรณ์ Android 4.4 (API ระดับ 19) ถึง Android 9 (API ระดับ 28)
Google Pay สําหรับบัตร
com.google.android.gms:play-services-pay:16.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS

รองรับอุปกรณ์ที่ใช้ Android 5.0 (API ระดับ 20) ขึ้นไป
reCAPTCHA Enterprise สําหรับการใช้เครื่องมือแอป
com.google.android.gms:play-services-recaptcha:17.0.1
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
SafetyNet API (รวมถึงเอกสารรับรองอุปกรณ์, การท่องเว็บอย่างปลอดภัย, reCAPTCHA และการยืนยันแอป)
com.google.android.gms:play-services-safetynet:18.0.1
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS
Google Tag Manager
com.google.android.gms:play-services-tagmanager:18.0.2
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
Tasks API บน Android
com.google.android.gms:play-services-tasks:18.0.2
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS, Wear OS
Acceleration Service สําหรับ Android
com.google.android.gms:play-services-tflite-acceleration-service:16.0.0-beta01
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
TensorFlow Lite GPU Delegate API สําหรับบริการ Google Play
com.google.android.gms:play-services-tflite-gpu:16.2.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
TensorFlow Lite Java API สําหรับบริการ Google Play
com.google.android.gms:play-services-tflite-java:16.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
TensorFlow Lite Support API สําหรับบริการ Google Play
com.google.android.gms:play-services-tflite-support:16.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
Thread Network API
com.google.android.gms:play-services-threadnetwork:16.0.0
โทรศัพท์ แท็บเล็ต
วิสัยทัศน์สําหรับอุปกรณ์เคลื่อนที่
com.google.android.gms:play-services-vision:20.1.3
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
Google Pay สําหรับการชําระเงินบน Android
com.google.android.gms:play-services-wallet:19.2.0-beta01
โทรศัพท์, แท็บเล็ต, อัตโนมัติ, Android Go, ChromeOS, Wear OS
API ชั้นข้อมูลที่สวมใส่ได้
com.google.android.gms:play-services-wearable:18.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, อัตโนมัติ, Android Go, ChromeOS, Wear OS