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">操作</string> <string name="title_notifications">设置</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- 构建并运行项目。
- 该应用将有两个标签页:“操作”和“设置”。导航到 设置 标签页。
- 点击 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 控制面板并向您注册的设备发送推送通知。
后续步骤
Anchor link to要了解更多信息,请参阅基本集成指南。