Android uses a push to implement the push function of third-party applications

PS: I used a push I feel that it is relatively simple to realize the push function of third-party applications The official documents are also very clear

Learning content:

1. Use a push to push third-party applications

Finally, I will give you a source code for all configurations. There are relevant configurations and documents to help you complete the configuration. I won't introduce them here

I don't think there is much to write, because the official documents have been very clear about how to configure and import jar packages The so file and the related configuration of the Android manifest file are written very clearly I'll give you a brief introduction here I won't talk about registering an account. There is no need to reduce these basic things

i.PushManager

Pushmanager is the core class to realize push. It can push control, set labels, set aliases, set default time, etc All interfaces are called by this object Therefore, we need to initialize the pushmanager object

Objects are created in a single column Therefore, the object obtained is unique Here, when the pushmanager object is obtained, the push service is initialized. After the interface is called, the push service runs in the background and sends the CID to the app through broadcasting In fact, the most important thing here is the broadcast. There is no key point in other things Just pay a little attention

ii. Getuipushreceiver app receives the broadcast of CID

This broadcast is the core class for receiving push messages. In fact, it is relatively simple to implement. First, get the pushmanager object, then initialize a push service, and judge the passed data in the onreceiver method. Here, only two states are judged: push notification and transparent message

In this way, through judgment, we can know whether to push notification or through message, etc Finally, we write an interface to expose to the outside world. In fact, we expose the interface to the activity. When we receive data changes in the broadcast or have data transferred, we need to inform the main process of the data changes through this interface. This is the purpose of exposing the interface Then in the main page, we only need to implement this interface

III. open push

The turnonpush (context) method is used to open the push. If we don't actively open the push, we can't receive the push message even if it is sent in the background It is on by default

IV. turn off push service

The turnoffpush (context) method is used to close the push service After this method is executed, the push service cannot be received. Note that if you want to receive the push again, you must use the turnonpush (context) method Other methods are invalid

v. Stop SDK service

stopService(context). After stopping the SDK service, the service will not stop running, but terminate the push and networking functions Restart requires calling the initialize () method or the turnonpush () method

All the basic things have been introduced. There are also some settings such as tags, silence time and binding aliases. If you are interested, you can study them yourself. Anyway, I haven't used them yet So don't move these modules first Let's see how to use a push background to push

First, we need to create our own application, and then we can get the data we want in the application configuration. The specific effects are as follows

Here are the data we want, appid, appkey, etc. These things need to be configured in the androidmanifest file After you make your own demo, you can send a push through the background

The title and content are required, and then you can always confirm, so that the message will be pushed out Open the push service on the app to receive the push I won't take a screenshot if I send a message through It should be noted that the transparent message is a string in JSON format A push provides us with Jason's formatting tool

Finally, put a source code. This source code cannot run because it uses my own background. You also need to create an account, use your own background to create an application, and then modify the appid, appkey and appsecret in the androidmanifest file And many documents are provided internally to help you integrate. Click download.

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
分享
二维码
< <上一篇
下一篇>>