php 友盟推送角标,android集成友盟推送实现离线在线推送及桌面图标角标设置
发布日期:2021-06-24 10:48:41 浏览次数:2 分类:技术文章

本文共 3305 字,大约阅读时间需要 11 分钟。

本人亲测有效,有问题欢迎评论,互相学习

1、集成友盟推送—根据友盟文档集成即可实现在线推送

2、集成后想要实现点击跳转到指定页面,那么就要根据后台返回的数据进行跳转

(1)在线推送—在application下实现此代码

UmengNotificationClickHandler notificationClickHandler =new UmengNotificationClickHandler() {

@Override

public void launchApp(Context context, UMessage msg) {

super.launchApp(context, msg);

Map extra = msg.extra;

if (extra.get("pushType").equals("1")) {

Intent intent =new Intent(context, NoticeBulletionDetailActivity.class);

intent.putExtra("notifyId",extra.get("businessId"));

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(intent);

}else if (

extra.get("pushType").equals("2")){

Intent intent =new Intent(context, PartyBuildNewsDetailActivity.class);

intent.putExtra("notifyId",extra.get("businessId"));

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(intent);

}

}

@Override

public void openUrl(Context context, UMessage msg) {

super.openUrl(context, msg);

}

@Override

public void openActivity(Context context, UMessage msg) {

super.openActivity(context, msg);

Toast.makeText(context, msg.msg_id, Toast.LENGTH_LONG).show();

Map extra = msg.extra;

if (extra.get("pushType").equals("1")) {

Intent intent =new Intent(context, NoticeBulletionDetailActivity.class);

intent.putExtra("notifyId",extra.get("businessId"));

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(intent);

}else if (extra.get("pushType").equals("2")){

Intent intent =new Intent(context, PartyBuildNewsDetailActivity.class);

intent.putExtra("notifyId",extra.get("businessId"));

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(intent);

}

}

@Override

public void dealWithCustomAction(Context context, UMessage msg) {

Toast.makeText(context, msg.custom, Toast.LENGTH_LONG).show();

}

};

mPushAgent.setNotificationClickHandler(notificationClickHandler);

MiPushRegistar.register(this,"xxxxxxxx","xxxxxxxxx");

HuaWeiRegister.register(this);

(2)离线推送—需要后台指定跳转页,该activity需要继承UmengNotifyClickActivity重写onMessage方法

public class MiPushActivity extends UmengNotifyClickActivity{

private WebView webView;

private TemplateTitle mTemplateTitle;

private String mTitle;

private String mUrlSign;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_mi_push);

webView =findViewById(R.id.web_build_push);

mTemplateTitle = findViewById(R.id.title_build_push);

}

@Override

public void onMessage(Intent intent) {

//此方法必须调用,否则无法统计打开数

super.onMessage(intent);

mBody = intent.getStringExtra(AgooConstants.MESSAGE_BODY);

}

private void displayView(String body) {

Gson gson =new Gson();

PushEntity entity = gson.fromJson(mBody,PushEntity.class);

String id = entity.extra.businessId;

if ("1".equals(entity.extra.pushType)){

mTitle ="公告";

mUrlSign = Constants.WEB_URL+"/a?notifyId="+id;

}else if ("2".equals(entity.extra.pushType)){

mTitle ="新闻";

mUrlSign = Constants.WEB_URL+"/a?id="+id;

}

webView.requestFocus();

mTemplateTitle.setTitleText(mTitle +"详情");

webView.getSettings().setJavaScriptEnabled(true);

syncCookie(mUrlSign);

webView.loadUrl(mUrlSign);

}

}

3、桌面图标的角标只能在代码中设置,友盟无法完成此操作,需要自己在代码中实现下载此jar包,亲测华为小米有效

下载地址:https://pan.baidu.com/s/1YfkPavA_6npt8mI-Szb7QQ

设置角标数字:

int badgeCount = 5;

ShortcutBadger.applyCount(mContext, badgeCount);

移除角标数字:

ShortcutBadger.removeCount(context);

or:ShortcutBadger.applyCount(mContext, 0);

转载地址:https://blog.csdn.net/weixin_32290249/article/details/116250951 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:oracle 排序的分析函数,Oracle SQL:使用分析排序函数
下一篇:用matlab仿真mmc环流抑制器,一种基于准PR控制原理的MMC阀组环流抑制方法

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月23日 14时21分58秒