关于前端:推送MOBPUSHAPI说明

8次阅读

共计 4463 个字符,预计需要花费 12 分钟才能阅读完成。

音讯监听接口 MobPushReceiver: 音讯监听接口(蕴含接管自定义音讯、告诉音讯、告诉栏点击事件、别名和标签变更操作等)
MobPush.addPushReceiver(MobPushReceiver receiver): 设置音讯监听
MobPush.removePushReceiver(MobPushReceiver receiver): 移除音讯监听
推送开关管制接口 MobPush.stopPush(): 进行推送(进行后将不会收到推送音讯,仅可通过 restartPush 从新关上)
MobPush.restartPush(): 从新关上推送服务
MobPush.isPushStopped(): 判断推送服务是否曾经进行
推送选项接口 MobPush.setSilenceTime(int startHour, int startMinute, int endHour, int endMinute): 设置告诉静音时段(开始工夫小时和分钟、完结工夫小时和分钟)
MobPush.setCustomNotification(MobPushCustomNotification customNotification): 设置自定义告诉款式
业务接口 MobPush.getRegistrationId(MobPushCallback callback):获取注册 id(可与用户 id 绑定,实现向指定用户推送音讯)
别名操作:(同时只能设置一个别名,可用来标识一个用户)
MobPush.setAlias(String alias):设置别名
MobPush.getAlias():获取以后设置的别名
MobPush.deleteAlias():删除别名
标签操作:(同时可设置多个标签,可用于多用户订阅标签的形式,批量推送音讯)
MobPush.addTags(String[] tags):增加标签
MobPush.getTags():获取所有已增加的标签
MobPush.deleteTags(String[] tags):删除标签
MobPush.cleanTags():革除所有已增加的标签
MobPushCustomeMessage: 自定义音讯实体类
MobPushNotifyMessage: 告诉音讯实体类
本地告诉 MobPush.addLocalNotification(MobPushLocalNotification notification):增加本地告诉
MobPush.removeLocalNotification(int notificationId):移除本地告诉
MobPush.clearLocalNotifications():清空本地告诉
MobPushLocalNotification:本地告诉音讯实体类,继承 MobPushNotifyMessage
API 错误码 API 返回的错误码阐明如下:(详见 MobPushErrorCode.java 阐明)
-1 网络申请失败
-2 申请谬误
性能自定义和扩大
前言:此性能仅仅是针对 push 的一些应用场景而进行自定义设定。比方,告诉被点击的时候:
形式一、通过界面 uri 进行 link 跳转
首先当初 Manifest 文件中进行指标 Activity 的 uri 设置,如下:

activity

android:name=".LinkActivity">

<intent-filter>

    <action android:name="android.intent.action.VIEW" />

    <category android:name="android.intent.category.DEFAULT" />

    <data

        android:host="com.mob.mobpush.link"

        android:scheme="mlink" />

</intent-filter>

</activity>
在 Mob 后盾进行推送时,通过 scheme://host 的格局,例如 mlink://com.mob.mobpush.link,如下地位填入:

配置好之后,推送就 App 就能够接管到推送间接关上指定的 Activity 界面了。
形式二、当 app 显示在前台的时候,会触发 MobPushReceiver 的 onNotifyMessageOpenedReceive 办法,MobPushNotifyMessage 参数则是回调的告诉详情,能够依据回调参数进行解决(不倡议应用,当过程被杀掉的状况下,启动利用后可能无奈执行到回调办法,因为此时可能还执行到未增加监听的代码);
形式三、不论 app 过程是否被杀掉,当点击告诉后拉起利用的启动页面,会触发启动 Activity 的 OnCreate 或 OnNewIntent 办法,通过 getIntent 办法拿到回传的 Intent,遍历 getExtras,能够拿到告诉详情(倡议应用);
依据形式二,MobPush 以两个场景为例子:
场景一、通过扩大参数实现页面的自定义跳转:

// 自定义扩大字段的 key,下发告诉的时候,在扩大字段应用这个 key

private final static String MOB_PUSH_DEMO_INTENT = “intent”;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

dealPushResponse(getIntent());

}

protected void onNewIntent(Intent intent) {

dealPushResponse(intent);

// 须要调用 setIntent 办法,不然前面获取到的 getIntent 都是上一次传的数据

setIntent(intent);

}

//OnCreate 和 OnNewIntent 办法都要同时解决这个逻辑

private void dealPushResponse(Intent intent) {

Bundle bundle = null;

if (intent != null) {

  bundle = intent.getExtras();

  if (bundle != null) {Set<String> keySet = bundle.keySet();

     for (String key : keySet) {if (key.equals("msg")) {MobPushNotifyMessage notifyMessage = (MobPushNotifyMessage) bundle.get(key);

           HashMap<String, String> params = notifyMessage.getExtrasMap();

           if(params != null && params.containsKey(MOB_PUSH_DEMO_INTENT)){

              // 此处跳转到指定页面

              openPage(params);

           }

        }

     }

  }

}

}

private void openPage(HashMap<String, String> params){

Intent intent = new Intent(this, JumpActivity.class);

intent.putExtra("key1", "value1");

intent.putExtra("key2", "value2");

intent.putExtra("key3", "value3");

// 如上 Intent,在 intent.toURI(); 之后失去的 String,如下所示,可利用这个办法辨认 Intent 传的参数,// 下发的参数能够依照上面的格局传,客户端接管后再转成 Intent, 若增加 action 等其余参数,可自行打印看 Srting 构造体;//#Intent;component=com.mob.demo.mobpush/.JumpActivity;S.key1=value1;S.key2=value2;S.key3=value3;end



String uri;

if(!TextUtils.isEmpty(params.get(MOB_PUSH_DEMO_INTENT))) {uri = params.get(MOB_PUSH_DEMO_INTENT);

    try {startActivity(Intent.parseUri(uri, 0));

    } catch (Throwable t){t.printStackTrace();

    }

}

}
场景二、通过扩大参数实现 web 界面的跳转:
代码同场景一一样,跳转页面的办法改成跳转 webview 页面就能够,通过参数辨认,拿到须要跳转的 Url 链接

private final static String MOB_PUSH_DEMO_URL = “url”;

//OnCreate 和 OnNewIntent 办法都要同时解决这个逻辑

private void dealPushResponse(Intent intent) {

Bundle bundle = null;

if (intent != null) {

  bundle = intent.getExtras();

  if (bundle != null) {Set<String> keySet = bundle.keySet();

     for (String key : keySet) {if (key.equals("msg")) {MobPushNotifyMessage notifyMessage = (MobPushNotifyMessage) bundle.get(key);

           HashMap<String, String> params = notifyMessage.getExtrasMap();

           if(params != null && params.containsKey(MOB_PUSH_DEMO_URL)){

              // 此处跳转到 webview 页面

              openUrl(params);

           }

        }

     }

  }

}

}

private void openUrl(HashMap<String, String> params){

String url;

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 页面,粘贴应用会找不到相干类

WebViewPage webViewPage = new WebViewPage();

webViewPage.setJumpUrl(url);

webViewPage.show(this, null);

}
下面两个场景的应用示例代码,能够参考官网 demo
https://github.com/MobClub/Mo…

正文完
 0