Simple usage of Android Xiaomi push

The company's projects need to be pushed. We choose to push with Xiaomi. After a period of exploration, we can finally simply use Xiaomi push.

1. Create an account and select message push after login:

2. Create a project after entering. After creating the project according to the steps, see the following

3. After the background configuration is completed, we will configure the code again. For the first time, we use Xiaomi to push my next demo, and then copy the useful ones into our own project:

First copy the jar package to your project

First, put in the class that inherits application

ID and key are obtained from the project created on Xiaomi open platform, and then added to the oncreate() method of application:

Where shouldinit() and handler:

To tell you the truth, demohandler is useless. It's just a toast prompt. I don't like it, so I hide the toast. The refreshlogoinfo() method in mainactivity:

Then we need to copy a broadcast class in the demo. Since the content is the same, I won't copy it. One of the methods is very important: onnotificationmessageclicked (context, mipushmessage message)

The function of this method is: when a message is pushed to your mobile phone, when you click the message in the notification bar, you can get the content of the message through message in this method.

Second, if you want to click the message in the notification bar to jump to the interface specified in your app, and execute it in this method, you only need to add a piece of code:

Finally, we need to configure some permissions of androidmanifest.xml. I won't put them together with the previous permissions. It's hard to distinguish them. You can find them in the demo and put them under the permissions

Add in < application / >

That's it.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>