เริ่มต้นใช้งาน Android SDK ฉบับย่อ
เริ่มต้นใช้งาน Pushwoosh Android SDK ด้วยตัวอย่างที่ง่ายและรวดเร็วนี้
ข้อกำหนดเบื้องต้น
Anchor link toในการผสานรวม Pushwoosh Android SDK เข้ากับแอปของคุณ คุณจะต้องมีสิ่งต่อไปนี้:
ดาวน์โหลดโปรเจกต์ตัวอย่าง
Anchor link toโคลนโปรเจกต์ตัวอย่างจาก GitHub:
git clone https://github.com/Pushwoosh/pushwoosh-android-sample
กำหนดค่าโปรเจกต์
Anchor link toวางไฟล์ google-services.json ของคุณในไดเรกทอรี pushwoosh-demoapp/app
ในไฟล์ build.gradle ของคุณ (Module: app) ให้อัปเดต
applicationId
ให้ตรงกับ package name ของคุณในไฟล์ res/values/strings.xml ให้แทนที่ค่าตัวยึดตำแหน่งด้วยข้อมูลเฉพาะของคุณ:
pushwoosh_app_id
: ใช้ Pushwoosh App Code ของคุณfcm_sender_id
: ใช้ Firebase Project Number ของคุณpushwoosh_api_token
: ใช้ Pushwoosh Device API Token ของคุณ
<resources> <string name="app_name">demoapp</string> <string name="title_home">Actions</string> <string name="title_notifications">Settings</string> <string name="pushwoosh_app_id">_YOUR_PUSHWOOSH_APP_ID_</string> <string name="fcm_sender_id">_YOUR_FIREBASE_PROJECT_ID_</string> <string name="pushwoosh_api_token">_YOUR_PUSHWOOSH_DEVICE_API_TOKEN_</string></resources>
รันโปรเจกต์
Anchor link to- บิลด์และรันโปรเจกต์
- แอปจะมีสองแท็บ: “Actions” และ “Settings” ไปที่แท็บ Settings
- แตะปุ่ม Register for Pushes
- ให้สิทธิ์สำหรับการแจ้งเตือนแบบพุช อุปกรณ์จะถูกลงทะเบียนกับ Pushwoosh
คุณควรเห็นรายการบันทึก (log) ลักษณะนี้:
Log level: INFO[RequestPermissionHelper] Requesting permissionsPushwoosh SDK initialized successfullyHWID: __HWID_OF_YOUR_DEVICE__APP_CODE: __YOUR_PUSHWOOSH_APP_ID__PUSHWOOSH_SDK_VERSION: __PUSHWOOSH_SDK_VERSION_INSTALLED__FIREBASE_PROJECT_ID: __YOUR_FIREBASE_PROJECT_ID__PUSH_TOKEN:User ID "__USER_ID_OF_THE_DEVICE__" successfully set
[NotificationManager] Registered for push notifications: __DEVICE_PUSH_TOKEN__
ส่งการแจ้งเตือนแบบพุช
Anchor link toกลับไปที่ Pushwoosh Control Panel และ ส่งการแจ้งเตือนแบบพุช ไปยังอุปกรณ์ที่ลงทะเบียนไว้ของคุณ
ขั้นตอนถัดไป
Anchor link toหากต้องการเรียนรู้เพิ่มเติม โปรดดูที่ คู่มือการผสานรวมพื้นฐาน