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**中,将占位符值替换为您的具体详细信息:
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 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,并向您注册的设备发送推送通知。
要了解更多信息,请参阅基本集成指南。