Firebase Cloud Messaging is a very good push notification service for most Android app, except it doesn't work in China. Google services are blocked over there.
Baidu Cloud Push is one of the push notification service that can work in China. They have iOS/Android client SDK, Java/PHP based server SDK, REST API, and is intergrated into Amazon SNS & Microsoft Azure's Notification Hub service.
I'm going to show you how do you integrate Baidu Cloud Push into Xamarin.Android project, and use it with Amazon SNS/Azure Notification Hub.
What you'll need.
- A Baidu account. A working phone number is required. Link for non-China base number
- A Baidu Cloud Push account. A valid Chinese ID, business address, China-based phone number is required. Link
- Amazon SNS account or Azure Notification Hub account
1. Download 'Baidu.Android.PushService' nuget
- Download this Nuget. It's a Xamarin.Android binding library for Baidu Push Service Android native SDK.
- Complete the additional setup instruction
2. Create the required permissions & registration in App Manifest
<script src="https://gist.github.com/xyfoo/39c9be7957500e7ee88861e5ee242514.js">3. Implement the push notification receiver
<script src="https://gist.github.com/xyfoo/aee457468cc5f091bdd91c4b6ea81c02.js">And initialize the class in your MainActivity OnCreate
function.
4. You're done!
Upon the app launch, your device will be registered with Baidu Cloud Push (generating a unique UserId
, channelId
) and a token
/regId
from your choice of push notification platform.
You can use those ID to do a push notificaiton to your device now.
The full project repository can be found here