Message push is an important part of App operation. In order to optimize the success rate of message push and reduce power and flow consumption, system-level push service is particularly important. As a result, Xiaomi and Meizu launched their own push platform, sharing system-level push service on MIUI and Flyme, so that the APP can normally receive push messages even if it is killed. In the future, more and more mobile phone manufacturers will launch their own push platforms, thus MixPush is born to reduce the development cost of integrating multiple push and improve the arrival rate of push.
The project is open source on Github
Github.com/joyrun/MixP…
Recommendation push platform
Millet push
Support for all Android platforms, features in MIUI system sharing system-level push, APP killed can also receive notification bar push. Dev.mi.com/console/app…
Meizu push
It only supports the Flyme system and cannot be used on non-Flyme systems. The feature is that system-level push is shared in the Flyme system, and notification bar push can be received even if the APP is killed. Open. Flyme. Cn/open – web/vi…
Push a push
The largest third-party push platform on Android platform with stable push messages. www.getui.com/cn/index.ht…
Schematic diagram
image.png
The principle of analysis
MixPush is only a framework to reduce the integration of multiple push services. MixPush does not have push functions itself, and all push functions are implemented by various push platforms. As can be seen from the schematic diagram, the client APP will register different push platforms according to different mobile phones. Two push services cannot be registered at the same time to avoid repeated receipt of push. However, the server does not consider the platform of the user’s mobile phone that needs to push the message, and uniformly pushes the message to all platforms, while the client will only receive the push message of a single platform according to the platform registered.
Android client configuration
Add the repository address and modify the build.gradle file in the root directory:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Copy the code
Select push platform, if not can refer to the source code to implement, add dependencies:
Dependencies {the compile 'com. Making. Joyrun. MixPush: client - the core: 1.0.0' / / will fill the compile 'com. Making. Joyrun. MixPush: client - mipush: 1.0.0' / / millet push the compile 'com. Making. Joyrun. MixPush: client - getui: 1.0.0' / / a push The compile 'com. Making. Joyrun. MixPush: client - meizu: 1.0.0' / / meizu, push the meizu push only support Flyme system, be sure to note}Copy the code
Create a service class that inherits MixPushIntentService to receive events:
public class PushIntentService extends MixPushIntentService { @Override public void OnReceivePassThroughMessage (MixPushMessage message) {Log. E (TAG, "received passthrough (AFP) - >" + message. The getContent ()); } @Override public void onNotificationMessageClicked(MixPushMessage message) { Log.e(TAG, "Notification message click ->" + message.getContent()); }}Copy the code
Configure androidmanifest.xml and register the service class
<manifest>
<application ...>
...
<service android:name=".PushIntentService"/>
</application>
</manifest>
Copy the code
Initializing the Application class, if not, create your own:
public class DemoApplication extends Application { public static final String MEIZU_APP_ID = "<MEIZU_APP_ID>"; public static final String MEIZU_APP_KEY = "<MEIZU_APP_KEY>"; public static final String MIPUSH_APP_ID = "<MIPUSH_APP_ID>"; public static final String MIPUSH_APP_KEY = "<MIPUSH_APP_KEY>"; @Override public void onCreate() { super.onCreate(); initPush(); } private void initPush() { MixPushClient.addPushManager(new MeizuPushManager(MEIZU_APP_KEY, MEIZU_APP_ID)); MixPushClient.addPushManager(new MiPushManager(MIPUSH_APP_ID, MIPUSH_APP_KEY)); MixPushClient.addPushManager(new GeTuiManager()); MixPushClient.setPushIntentService(PushIntentService.class); MixPushClient.setSelector(new MixPushClient.Selector() { @Override public String select(Map<String, MixPushManager> pushAdapterMap, String brand) { // return GeTuiManager.NAME; Return super.select(pushAdapterMap, brand) return super.select(pushAdapterMap, brand); }}); / / configuration, receive push message service class MixPushClient. SetPushIntentService (PushIntentService. Class); . / / registered push MixPushClient registerPush (this); SetAlias (this, getUserId())); mixPushClient.setalias (this, getUserId()); Mixpushclient.settags (this," Guangdong "); mixPushClient.settags (this," Guangdong "); } private String getUserId(){ return "103"; }}Copy the code
Modify the build.gradle file of APP, configure the APP ID and other information
android { defaultConfig { ... manifestPlaceholders = [ GETUI_APP_ID : "<GETUI_APP_ID>", GETUI_APP_KEY : "<GETUI_APP_KEY>", GETUI_APP_SECRET : "< GETUI_APP_SECRET >," PACKAGE_NAME: "< APP package name >"]}}Copy the code
Customize the notification bar notification icon
Millet push
At present, the notification icon display rules are as follows:
- If a drawable file named miPUSH_notification and miPUSH_SMALL_notification exists in the app, use the drawable of miPUSH_notification as the large icon of the notification. The drawable of miPUSH_SMALL_notification is used as a small icon for notifications.
- If only one of the drawable files exists in the app, use that drawable as the notification icon.
- If the drawable files do not exist in the app, use the icon of the app as the notification icon. In MIUI, the icon of the notification bar is uniformly displayed as the icon of the APP, which cannot be customized.
Push a push
To change the default notification bar tip icon, Drawable -ldpi/, res/drawable-mdpi/, res/drawable-hdpi/, res/drawable-xhdpi/, res/drawable-xxhdpi/ Place the corresponding size file named push.png image.
ldpi: 48*48
mdpi: 64*64
hdpi: 96*96
xhdpi: 128*128
xxhdpi: 192*192
Copy the code
Meizu push
Same as xiaomi push.
Pay attention to
- Meizu push only supports Flyme system, so be sure to pay attention to it.
Server configuration test
Currently, only the Java server code is available. If the server uses other languages, you can follow the design guidelines to develop it yourself.
Copy the code and JAR packages into the project.
The server pushes tests
Public class MixPushServerTest {public static final String APP_PACKAGE_NAME = "<APP package name >"; public static final String MIPUSH_APP_SECRET_KEY = "<MIPUSH_APP_SECRET_KEY>"; public static final Long MEIZU_APP_ID = <MEIZU_APP_ID>; public static final String MEIZU_APP_SECRET_KEY = "<MEIZU_APP_SECRET_KEY>"; public static final String GETUI_APP_ID = "<GETUI_APP_ID>"; public static final String GETUI_APP_KEY = "<GETUI_APP_KEY>"; public static final String GETUI_MASTER_SECRET = "<GETUI_MASTER_SECRET>"; public static final String GETUI_URL = "http://sdk.open.api.igexin.com/apiex.htm"; static { MixPushServer.addPushServerManager(new MiPushServerManager(APP_PACKAGE_NAME, MIPUSH_APP_SECRET_KEY)); MixPushServer.addPushServerManager(new MeizuPushServerManager(MEIZU_APP_ID, MEIZU_APP_SECRET_KEY)); MixPushServer.addPushServerManager(new GeTuiPushServerManager(GETUI_APP_ID, GETUI_APP_KEY, GETUI_MASTER_SECRET, GETUI_URL)); } String title = "title"; String description = "description"; String json = "{\"name\":\"Wiki\",\"age\":24}"; @Test public void sendNotifyToAll() throws Exception { MixPushServer.sendNotifyToAll(title, description, json); } @Test public void sendMessageToAll() throws Exception { MixPushServer.sendMessageToAll(json); } @Test public void sendMessageToAlias() throws Exception { MixPushServer.sendMessageToAlias("100", json); } @ Test public void sendMessageToTags () throws the Exception {MixPushServer. SendMessageToTags (" guangdong ", json); } @Test public void sendNotifyToAlias() throws Exception { MixPushServer.sendNotifyToAlias("100", title, description, json); } @ Test public void sendNotifyToTags () throws the Exception {MixPushServer. SendNotifyToTags (" guangdong province ", the title, description, json); }}Copy the code
If you don’t use any of the above, you can do it yourself.