Push Notification Services v1.9

Setting up Push Notifications with Baidu

This document describes how developers can set up the Pivotal Cloud Foundry (PCF) Push Notification Service with the Baidu platform so their apps can send push notifications to Android devices.


The procedures in this document require the following:

  • You must have access to a PCF environment with the Push Notification Service installed.
  • You must have Android Studio 2.2 or later installed on your machine.
  • You must have the Google Repository from the Android SDK Manager.
  • You must have the Push Android SDK 1.7 or later from Github.
  • The devices that you want to send push notifications to must run Android 2.3 (Gingerbread) or later.
  • The devices that you want to send push notifications to must have Google Play Services 9.8.0 or later.

Prepare a Baidu Project

Follow these steps to prepare a Baidu application for your app.

  1. Navigate to the Baidu Push website.
  2. Select Log in (登录) or Register (注册) at the top right and log in or register.
  3. Select your username at the top right to view your application list.
  4. Select Create a new application (创建新应用), enter a name and continue.
  5. On the App Configuration (应用配置) screen, select Android, enter your app’s package name and select Save (保存).
  6. Back on the application list page, select Application Configuration (应用配置) to obtain the API Key and Secret Key.

Configure Your Push Dashboard

Follow the steps below to navigate to the Push dashboard and configure the Push Notification service.

You can navigate to the Push dashboard using either Apps Manager or the Cloud Foundry Command Line Interface (cf CLI). Use the cf CLI instructions if you did not enable the Push Apps Manager errand when deploying Elastic Runtime.

  1. In a browser, navigate to apps.YOUR-SYSTEM-DOMAIN.
  2. Select the System org and the Push-notifications space.
  3. Select the Services tab.
  4. Select the PCF Push Notification Service row and select the Manage link.
  1. Open a terminal window and log in:

    $ cf login -a https://api.YOUR-SYSTEM-DOMAIN -u USERNAME -p PASSWORD
  2. Target the correct org and space:

    $ cf target -o system -s push-notifications
  3. Run the following command:

    $ cf service push-service-instance
  4. Copy the URL from the Dashboard field and paste it into your browser.

Configure the Push Notification Service

Follow these steps to configure the Push backend by creating a new platform for the sample app.

  1. In the Push dashboard, select the + icon from the left to create a new app to send push notifications to, either the push sample app or the push demo app.
    • Enter a Name and Description.
  2. Once you create an app, select the Configuration tab for that app.
  3. Select Add New Platform.
  4. Enter a Name and Description, and choose a Mode.
  5. For Type, select Android-Baidu.
  6. Select the pencil icon to edit the platform.
  7. In the Baidu API Key field, enter the API key that you recorded earlier.
  8. In the Baidu Secret field, enter the secret key that you recorded earlier.

Note: You can add multiple Baidu Platforms with keys from different Baidu applications, depending on how your Baidu applications and projects are organized. There is no requirement that all Baidu Platforms use the same keys in the Push backend.

Run the App on Your Device

Follow these steps to compile and deploy the app on your Android device.

  1. Navigate to the Push Android Samples repository.
  2. Clone the repository to your workspace.
  3. Checkout the release_v1.9 branch, or the branch of a later version.
  4. Ensure the baiduDebug or baiduRelease build variant is selected. The Android sample apps are multi-flavor: Baidu and FCM can both be built from this repository.
  5. Provide a keystore location for debug signingConfigs in the respective project’s build.gradle file. Optionally, remove this block.
  6. Populate the MainActivity configuration:
    • VARIANT_UUID with the platform UUID of the Baidu platform created in the previous section.
    • VARIANT_SECRET with the platform secret of the Baidu platform created in the previous step.
    • BASE_SERVER_URL with the server address to your push backend API in the form of https://push-api.YOUR-SYSTEM-DOMAIN. For more information, see API URL.
  7. Compile and deploy the application to your Android device.

Once the application registers with the Push backend, it can receive push notifications. To verify that your device registered, see the Devices tab in the Push dashboard. The device Type field displays a Baidu paw logo.

You can also send test pushes to the device from the Push dashboard.

Note: If you send a test push to your device from the Push dashboard, ensure the app is not open on your device. You cannot see the test push while the app is open.

Create a pull request or raise an issue on the source for this page in GitHub