หากต้องการพัฒนาแอปโดยใช้ 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 ในแอป ให้ทําตามขั้นตอนต่อไปนี้
เปิดไฟล์
build.gradle
ภายในไดเรกทอรีโมดูลของแอปสําหรับ SDK แต่ละรายการที่แอปต้องใช้ ให้รวมทรัพยากร Dependency สําหรับ SDK นั้น หน้านี้จะมีส่วนที่แสดงการอ้างอิงบริการ Google Play ทั่วไปสําหรับแอป Android คุณอาจต้องการเพิ่มทรัพยากร Dependency ของ Firebase ไปยังโปรเจ็กต์ด้วย
บันทึกการเปลี่ยนแปลงและซิงค์โครงการ
ข้อมูลโค้ดต่อไปนี้แสดงตัวอย่างไฟล์ 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 ได้ คุณกรองรายการตามประเภทอุปกรณ์ได้โดยเลือกปุ่มใดปุ่มหนึ่ง และค้นหากรณีการใช้งานที่เจาะจงหรือชื่อการอ้างอิงได้โดยป้อนข้อความลงในช่องที่ปรากฏหลังปุ่ม
กรณีการใช้งานและชื่อการอ้างอิง | อุปกรณ์ที่รองรับ |
---|---|
โฆษณาบนอุปกรณ์เคลื่อนที่ของ Googlecom.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 สําหรับ Androidcom.google.android.gms:play-services-analytics:18.0.2 |
เลิกใช้งานแล้ว โปรดใช้ Google Analytics สําหรับ Firebase แทน |
ดัชนีแอปcom.google.android.gms:play-services-appindex:16.1.0 |
โทรศัพท์, แท็บเล็ต, Android TV |
รหัสชุดแอป Androidcom.google.android.gms:play-services-appset:16.0.2 |
โทรศัพท์, แท็บเล็ต, Android TV, ChromeOS |
Google Sign-In สําหรับ Androidcom.google.android.gms:play-services-auth:20.5.0 |
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS |
SMS Fetcher APIcom.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 APIcom.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 Castcom.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 TVcom.google.android.gms:play-services-cast-tv:21.0.0 |
Android TV |
Google Code Scannercom.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 สําหรับ Androidcom.google.android.gms:play-services-fitness:21.1.0 |
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS, Wear OS |
บริการเกมของ Google Play เวอร์ชัน 2 สําหรับ Androidcom.google.android.gms:play-services-games-v2:17.0.0 |
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS |
Google Play Games Services v2 Native C SDK สําหรับ Androidcom.google.android.gms:play-services-games-v2-native-c:17.0.0-beta1 |
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS |
บริการเกมของ Google Play เวอร์ชัน 1 สําหรับ Androidcom.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 Instantcom.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 สําหรับ Androidcom.google.android.gms:play-services-maps:18.1.0 |
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS, Wear OS |
การสแกนบาร์โค้ด ML Kitcom.google.android.gms:play-services-mlkit-barcode-scanning:18.2.0 |
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS |
การตรวจจับใบหน้า ML Kitcom.google.android.gms:play-services-mlkit-face-detection:17.1.0 |
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS |
การติดป้ายกํากับรูปภาพ ML Kitcom.google.android.gms:play-services-mlkit-image-labeling:16.0.8 |
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS |
ป้ายที่กําหนดเองสําหรับอิมเมจ ML Kitcom.google.android.gms:play-services-mlkit-image-labeling-custom:16.0.0-beta4 |
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS |
การระบุภาษาของ ML Kitcom.google.android.gms:play-services-mlkit-language-id:17.0.0 |
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS |
สมาร์ทรีพลายใน ML Kitcom.google.android.gms:play-services-mlkit-smart-reply:16.0.0-beta1 |
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS |
การจดจําข้อความ ML Kitcom.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 Managercom.google.android.gms:play-services-tagmanager:18.0.2 |
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS |
Tasks API บน Androidcom.google.android.gms:play-services-tasks:18.0.2 |
โทรศัพท์, แท็บเล็ต, Android TV, อัตโนมัติ, Android Go, ChromeOS, Wear OS |
Acceleration Service สําหรับ Androidcom.google.android.gms:play-services-tflite-acceleration-service:16.0.0-beta01 |
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS |
TensorFlow Lite GPU Delegate API สําหรับบริการ Google Playcom.google.android.gms:play-services-tflite-gpu:16.2.0 |
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS |
TensorFlow Lite Java API สําหรับบริการ Google Playcom.google.android.gms:play-services-tflite-java:16.1.0 |
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS |
TensorFlow Lite Support API สําหรับบริการ Google Playcom.google.android.gms:play-services-tflite-support:16.1.0 |
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS |
Thread Network APIcom.google.android.gms:play-services-threadnetwork:16.0.0 |
โทรศัพท์ แท็บเล็ต |
วิสัยทัศน์สําหรับอุปกรณ์เคลื่อนที่com.google.android.gms:play-services-vision:20.1.3 |
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS |
Google Pay สําหรับการชําระเงินบน Androidcom.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 อีกหลายรายการดังที่แสดงในตารางต่อไปนี้ โปรดทราบว่าปุ่มที่ปรากฏก่อนตารางก่อนหน้า จะไม่เปลี่ยนข้อมูลที่แสดงในตารางนี้
ชื่อกรณีและปลั๊กอิน 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 |