An overview of the

The company is going to adopt the push platform as a third-party push platform. As the no.1 bird of the client, I have graduated for 0.1 years. The Leader is going to give me this simple and independent function point to deal with, so I nervously open the official website integration document to learn. As a matter of fact, as early as in my sophomore year, I integrated a push SDK, walked around and came back to integrate a push PUSH SDK, and found that now the push SDK is really more convenient than that year. This time, Android push SDK is integrated. I hope this article can help students integrate push push more quickly.

Mind mapping

The detailed steps

Download the demo

My master told me that the first step to integrate all kinds of SDKS is to download a Demo and run it to see what the ghost is. I dare not ask, I dare not say, first to download a Demo play. I chose the domestic version of the push SDK, you can choose to download the version. Using AS 3.1 to run the Getui_SDK_Demo_AS_maven project directly, the following interface appears (my personal parameters have been manually mosaiced here).

Create a push application

After watching the Demo, I opened the official website integration document in panic, the original parameters are required to create an application to get, and CID is a push SDK callback, nothing to say, then “register login – create an application – get configuration” three combo

Register your login account:

Create an

After logging in successfully, click my app to enter, and then click “Create App” in the upper right corner to create your own app. Because I have already created it, there is a mosaics as thick as the wall 🐩🐩🐩

Fill in the basic information of your APP

Obtaining Configuration Data

Since I have completed the registration, the interface after filling out is up to everyone’s imagination. After the application is created successfully, you can view the configuration information bound to the APP we created.

The package name of the project in the Demo was changed into the package name of the APP created by myself. The appID and other information were also replaced. It was found that the CID was obtained successfully
Once you get cid, integration is 90 % complete!!

Add dependencies and configurations

I integrated the SDK version 2.13.2.0 using Maven’s way. I chose Maven for easy (lazy) integration! If you choose manual integration, please take a look at their data pack first

Various resources, I chose Maven integration, so the JAR package & so do not need to import

Add maven repository

  • Add maven library to build. Gradle in the project root directory. Otherwise, the jar package will not be loaded
allprojects {
    repositories {

        maven {
          url 'http://mvn.gt.igexin.com/nexus/content/repositories/releases'}}}Copy the code
  • Configure the JAR package in build.gradle in the project /app directory
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com. Getui: SDK: 2.13.2.0'
}
Copy the code

Configure the appID created before

According to the gourd, here directly from the demo side of the copy over to be careful, carefully check each parameter, if there is a space or Appid and AppKey written in reverse this kind of stupid error really want to check to cry 😭😭😭

manifestPlaceholders = [
    GETUI_APP_ID : "Your APPID",
    GETUI_APP_KEY : "Your APP_KEY",
    GETUI_APP_SECRET : "Your APP_SECRET"
]
Copy the code

Import a push res file

Don’t forget, I’ve poked holes in this area before, so files are no longer needed with Maven integration, remember!

  • Import the Getui_SDK_Demo_AS_maven/ resource /res file to app/ SRC /main/res in your project

Configure optional permissions

Optional permissions. I wrote them here because I need them for my project

<! -> <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/ > <! -- Supports three push 3.0 electronic fence function --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Copy the code

Configure a user-defined service

Demo also configured a custom service, I also made, the official website has such a sentence

To ensure the stable operation of the push Service on some mainstream models, starting from 2.9.5.0, Gipush supports third-party applications to use user-defined services as the carrier of the push Service

All said so, bird brother I do not say two words on a new custom service, empty implementation can be

package com.xinwenwang.xy;

import com.igexin.sdk.PushService;

public class XyPushService extends PushService {

}

Copy the code

Don’t forget to register your new service in AndroidManifest.xml

<service
  android:name="com.xxxx.yyyy.XyPushService"
  android:exported="true"
  android:label="PushService"
  android:process=":pushservice">
</service>
Copy the code

If you think deeply, you can understand why you want to add an empty implementation of the service, just like the integration of wechat sharing, wechat sharing also requires inheritance of a specified activity.

Write the integration

It’s time to initialize the SDK 🤷♀️🤷♀️🤷

To initialize the SDK

com.igexin.sdk.PushManager.getInstance().initialize(getApplicationContext(), com.xxxx.yyyy.XyPushService.class);

Copy the code

I’m initializing a push in the open screen page, so you can do whatever you want, as long as the activity is initialized, it is recommended to initialize as early as possible

Received the push service event

So the question is, with so many things above, how to receive push messages or pass-through? Have a confused water! I ran back to look at the Demo, found that there is a Demo called DemoIntentService, open a look inside there are a lot of callback, bird brother said really exciting ah, Demo understand thoroughly, project integration fast! You are advised to copy DemoIntentService from Demo to your own project. If you need to modify the contents of DemoIntentService, feel free to do so. Remember to change a name, otherwise in their own projects inside really too low! My working name is XyPushIntentService.

  • In androidmanifest.xml, configure the IntentService class above:
<! -- user defined service (GTIntentService) --> <service android:name=".XyPushIntentService"
            android:permission="android.permission.BIND_JOB_SERVICE"/>
Copy the code
  • After the push SDK is initialized, register the above IntentService class
/ / XyPushIntentService receive for third-party custom push service event class PushManager. GetInstance () registerPushIntentService (getApplicationContext (), XyPushIntentService.class);Copy the code

test

Finally integrated, import the above things need to be careful ha, missed a step some you feel uncomfortable. Once the project is running, XyPushIntentService will have a cid callback. The most intuitive way to do this is to enter clientid in logcat and see the console output log. The clientid corresponds to the unique identifier of the APP on the device.

Here just created a very simple style for reference only, I see this interface function estimate can meet the various operation of the gameplay, I will not make a fool of myself :). When pushing test messages, the application must be in the foreground, in the foreground, in the foreground, the important things say three times

The first integration of such a large SDK made me unexpected and smooth. My friends and I were 😮 and surprised by 😮. Later, I read the document of the next push carefully, and their functions were still very complete. I have to say, their technical support service is really strong, and the response is fast and accurate. Now I have to rush to write bugs, goodbye 👋👋👋~~~

The original link: blog.csdn.net/u013651405/… Author: when you are full, you want to sleep

Industry frontier, mobile development, data modeling and other dry content, all in the public account: Gepu Technology Institute