เริ่มต้นใช้งาน 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ให้ตรงกับชื่อแพ็กเกจของคุณ -
ใน res/values/strings.xml แทนที่ค่า placeholder ด้วยรายละเอียดเฉพาะของคุณ:
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 entry ลักษณะนี้:
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หากต้องการเรียนรู้เพิ่มเติม โปรดดูที่ คู่มือการผสานรวมพื้นฐาน