当前位置: 首页 > Web前端 > HTML

推送MOBPUSH-API说明

时间:2023-03-29 10:47:48 HTML

消息监听接口MobPushReceiver:消息监听接口(包括接收自定义消息、通知消息、通知栏点击事件、别名和标签更改操作等)MobPush.addPushReceiver(MobPushReceiverreceiver):设置消息监听MobPush.removePushReceiver(MobPushReceiverreceiver):去掉消息监听推送开关控制接口MobPush.stopPush():停止推送(停止后不会收到推送消息,只能通过restartPush重新开启)MobPush.restartPush():重新开启推送ServiceMobPush.isPushStopped():判断推送服务是否停止推送选项接口MobPush.setSilenceTime(intstartHour,intstartMinute,intendHour,intendMinute):设置通知静默期(开始时间时分,结束时间时分)minute)MobPush.setCustomNotification(MobPushCustomNotificationcustomNotification):设置自定义通知样式业务接口MobPush.getRegistrationId(MobPushCallbackcallback):获取注册id(可以和userid绑定,给指定用户推送消息)Alias操作:(只能同时设置一个Alias,可以用来标识一个用户)MobPush.setAlias(Stringalias):设置别名MobPush.getAlias():获取当前设置的别名多用户订阅标签,批量推送消息)MobPush.addTags(String[]tags):添加标签MobPush.getTags():获取所有添加的标签MobPush.deleteTags(String[]tags):删除标签MobPush.cleanTags():清除所有添加的标签MobPushCustomeMessage:自定义消息实体类MobPushNotifyMessage:通过已知消息实体类本地通知MobPush.addLocalNotification(MobPushLocalNotificationnotification):添加本地通知MobPush.removeLocalNotification(intnotificationId):移除本地通知MobPush.clearLocalNotifications():清除本地通知MobPushLocalNotification:本地通知消息实体类,继承MobPushNotifyMessageAPI错误码API返回的errorcode解释如下:(详见MobPushErrorCode.java说明)-1网络请求失败-2请求错误函数定制和扩展例如,点击通知时:方法一、通过界面uri链接跳转首先在Manifest文件中设置目标Activity的uri,如下:activityandroid:name=".LinkActivity"><动作android:name="android.intent.action.VIEW"/>在Mob后台推送时,通过scheme://host的格式,比如mlink://com.mob.mobpush.link,填写下面位置:配置后,推送后,App可以接收推送,直接打开指定的Activity界面。方法二,当app显示在前台时,会触发MobPushReceiver的onNotifyMessageOpenedReceive方法。MobPushNotifyMessage参数为回调通知详情,可以根据回调参数进行处理(不推荐,当进程被kill掉,应用启动后可能无法执行回调方法,因为没有被调用的代码添加到监控此时可能仍会执行);方法三,无论app进程是否被kill,当点击通知拉起应用启动页时,会触发启动Activity的OnNewIntent方法的OnCreate或OnCreate,通过获取返回的IntentgetIntent方法,遍历getExtras,获取通知详情(推荐);根据第二种方式,MobPush以两种场景为例:场景1.通过扩展参数实现页面的自定义跳转Turn://自定义扩展字段的key。发送通知时,在扩展字段中使用此键。privatefinalstaticStringMOB_PUSH_DEMO_INTENT="intent";protectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);dealPushResponse(getIntent());}protectedvoidonNewIntent(Intentintent){dealPushResponse(intent);//setIntent方法需要调用,否则后面获取到的getIntent就是最后一次上传的数据setIntent(intent);}//OnCreate和OnNewIntent方法这个逻辑必须同时处理;if(intent!=null){bundle=intent.getExtras();if(bundle!=null){SetkeySet=bundle.keySet();for(Stringkey:keySet){if(key.equals("msg")){MobPushNotifyMessagenotifyMessage=(MobPushNotifyMessage)bundle.get(key);HashMapparams=notifyMessage.getExtrasMap();if(params!=null&¶ms.containsKey(MOB_PUSH_DEMO_INTENT)){//this跳转到指定页面"value1");intent.putExtra("key2","value2");intent.putExtra("key3","value3");//如上Intent,intent.toURI();后得到的String,如下As如图所示,这个方法可以用来识别Intent传递的参数。//发送的参数可以按照下面的格式传递,客户端收到后可以转化为Intents。如果加上其他的参数比如action,您可以自己打印它们以查看Srting结构;//#Intent;component=com.mob.demo.mobpush/.JumpActivity;S.key1=value1;S.key2=value2;S.key3=value3;endStringuri;如果(!TextUtils.isEmpty(标准ams.get(MOB_PUSH_DEMO_INTENT))){uri=params.get(MOB_PUSH_DEMO_INTENT)T);尝试{startActivity(Intent.parseUri(uri,0));}catch(Throwablet){t.printStackTrace();}}}场景二、通过扩展参数实现web界面跳转:代码同场景一,同理,跳转到页面的方法可以改为跳转到webview页面。通过参数识别,得到需要跳转的Url链接。privatefinalstaticStringMOB_PUSH_DEMO_URL="url";//OnCreate和OnNewIntent方法必须同时处理这个();if(bundle!=null){SetkeySet=bundle.keySet();for(Stringkey:keySet){if(key.equals("msg")){MobPushNotifyMessagenotifyMessage=(MobPushNotifyMessage)bundle.get(key);}HashMapparams=notifyMessage.getExtrasMap();if(params!=null&¶ms.containsKey(MOB_PUSH_DEMO_URL)){//这里跳转到webview页面openUrl(params);}}}}}}privatevoidopenUrl(HashMapparams){Stringurl;if(!TextUtils.isEmpty(params.get(MOB_PUSH_DEMO_URL))){url=params.get(MOB_PUSH_DEMO_URL);}else{url="http://m.mob.com";}if(!url.startsWith("http://")&&!url.startsWith("https://")){url="http://"+url;}System.out.println("url:"+url);//以下代码是开发者自定义的跳转webview页面,粘贴时会找不到相关的类。WebViewPagewebViewPage=newWebViewPage();webViewPage.setJumpUrl(url);webViewPage.show(this,null);}以上两种场景的示例代码,可以参考官方demohttps://github.com/MobClub/莫...

最新推荐
猜你喜欢