The company used it when developing the app, but the official documents of Youmeng are vague; roughly sort out the processing process from integrating Youmeng push to opening push message; if there is any inappropriate processing, please correct!!!!
Integrated push function
The alliance pushes the official document react native https://developer.umeng.com/docs/66632/detail/67587
- Add jar package. You can select the corresponding function jar package and add it to your android project;
- Import project module after adding jar package, import and reference the push project to your own project
- To add a bridge file, you need to add three files, which can be copied directly in the demo
- MainActivity integration code
//onCreate PushModule.initPushSDK(this); PushAgent.getInstance(this).onAppStart();
- After adding code to MainApplication and adding pacageList
//onCreate SoLoader.init(this, /* native exopackage */ false); //This initialization interface must be called for initialization of component-based basic library, statistics SDK / push SDK / share SDK RNUMConfigure.init(context, appKey, channel(Umeng), UMConfigure.DEVICE_TYPE_PHONE, secret); // initUpush();
At this point, you can receive the push message. In the rn page, you can call the method in the bridge file to obtain the DeviceToken and other information
Adding notification message click event involves not describing in detail from the native call rn method (how to send message event)
// An highlighted block private void initUpush() { PushAgent mPushAgent = PushAgent.getInstance(this); handler = new Handler(getMainLooper()); //sdk on notification sound mPushAgent.setNotificationPlaySound(MsgConstant.NOTIFICATION_PLAY_SDK_ENABLE); // sdk turn off notification sound // mPushAgent.setNotificationPlaySound(MsgConstant.NOTIFICATION_PLAY_SDK_DISABLE); // The notification voice is controlled by the server // mPushAgent.setNotificationPlaySound(MsgConstant.NOTIFICATION_PLAY_SERVER); // mPushAgent.setNotificationPlayLights(MsgConstant.NOTIFICATION_PLAY_SDK_DISABLE); // mPushAgent.setNotificationPlayVibrate(MsgConstant.NOTIFICATION_PLAY_SDK_DISABLE); UmengMessageHandler messageHandler = new UmengMessageHandler() { /** * Callback method of custom message */ @Override public void dealWithCustomMessage(final Context context, final UMessage msg) { handler.post(new Runnable() { @Override public void run() { // TODO Auto-generated method stub // Click or ignore the processing method of custom message boolean isClickOrDismissed = true; if (isClickOrDismissed) { //Click statistics of custom messages UTrack.getInstance(getApplicationContext()).trackMsgClick(msg); } else { //Ignore statistics for custom messages UTrack.getInstance(getApplicationContext()).trackMsgDismissed(msg); } Toast.makeText(context, msg.custom, Toast.LENGTH_LONG).show(); } }); } /** * Callback method of custom notification bar style */ @Override public Notification getNotification(Context context, UMessage msg) { switch (msg.builder_id) { case 1: Notification.Builder builder = new Notification.Builder(context); RemoteViews myNotificationView = new RemoteViews(context.getPackageName(), R.layout.notification_view); myNotificationView.setTextViewText(R.id.notification_title, msg.title); myNotificationView.setTextViewText(R.id.notification_text, msg.text); myNotificationView.setImageViewBitmap(R.id.notification_large_icon, getLargeIcon(context, msg)); myNotificationView.setImageViewResource(R.id.notification_small_icon, getSmallIconId(context, msg)); builder.setContent(myNotificationView) .setSmallIcon(getSmallIconId(context, msg)) .setTicker(msg.ticker) .setAutoCancel(true); return builder.getNotification(); default: //The default value is 0. If the filled builder u id does not exist, the default value is also used. return super.getNotification(context, msg); } } }; mPushAgent.setMessageHandler(messageHandler); /** * For the callback processing of custom behavior, refer to the document: advanced function - display and reminder of notification - Custom notification opening action * UmengNotificationClickHandler It is called in BroadcastReceiver, so * If you need to start the activity, you need to add intent.flag? Activity? New? Task * */ UmengNotificationClickHandler notificationClickHandler = new UmengNotificationClickHandler() { @Override public void dealWithCustomAction(Context context, final UMessage msg) { super.dealWithCustomAction(context,msg); Log.d("umeng---------",msg.extra.toString()); } }; //The user-defined notification handler is used to process message notifications in combination with the alliance statistics. Refer to http://bbs.umeng.com/thread-11112-1-1.html //CustomNotificationHandler notificationClickHandler = new CustomNotificationHandler(); mPushAgent.setNotificationClickHandler(notificationClickHandler); //Register push service will call back this interface every time register is called mPushAgent.register(new IUmengRegisterCallback() { @Override public void onSuccess(String deviceToken) { UmLog.i(TAG, "device token: " + deviceToken); } @Override public void onFailure(String s, String s1) { UmLog.i(TAG, "register failed: " + s + " " + s1); } }); }
Welcome to correct!!!