开启push模块,调用app的消息推送功能

阅读: 评论:0

开启push模块,调用app的消息推送功能

开启push模块,调用app的消息推送功能

搞了一周的app提醒,其实中间提示了错误 打包时未添加push模块,怎么整都整不出来,后来问了才知道这是因为没有开启push模块,无需开启unipush 只是点击push模块就可以了!

项目是使用后问socket连接发送的消息提醒 ,主要是用于内部网络的,所以只需要调用系统的消息框推送模块即可,消息提醒弹窗

function android_notify(content = '', data = {}) {// #ifdef APP-PLUS  var title = '通知标题';console.log('准备通知');console.log(plus.os.name);//Android平台下才使用此推送  if (plus.os.name != 'Android') {return false;}//随机生成通知ID  var NotifyID = Math.floor(Math.random() * 10000) + 1;var main = plus.android.runtimeMainActivity();var Context = plus.android.importClass(&#t.Context");var NotificationManager = plus.android.importClass("android.app.NotificationManager");var nm = SystemService(Context.NOTIFICATION_SERVICE);var Notification = plus.android.importClass("android.app.Notification");var Intent = plus.android.importClass(&#t.Intent");var PendingIntent = plus.android.importClass("android.app.PendingIntent");var intent = new Intent(main, Class());//传递参数  var payload = {'msg': content,'notify_id': NotifyID,'data': data};intent.putExtra("receive", JSON.stringify(payload));//Activity的第二个参数需要设置为随机数,否则多个通知时会导致前面的通知被后面的通知替换Extra的数据  var pendingIntent = Activity(main, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);var SystemVersion = plus.os.version;var firstVersionNumber = Number(SystemVersion.split('.')[0]);var r = plus.android.importClass("android.R");var mNotification;//判断当前系统版本在8.0及以上  if (firstVersionNumber >= 8) {var NotificationChannel = plus.android.importClass('android.app.NotificationChannel');var channel = new NotificationChannel("s" + NotifyID, "1", NotificationManager.IMPORTANCE_HIGH);nm.createNotificationChannel(channel);Notification = plus.android.importClass("android.app.Notification");mNotification = new Notification.Builder(main, "s" + NotifyID);} else {Notification = plus.android.importClass("android.app.Notification");mNotification = new Notification.Builder(main);}mNotification.setContentTitle(title) //设置标题  mNotification.setContentText(content); //设置内容  //mNotification.setSubText('');        //子内容暂时去掉  mNotification.setAutoCancel(true); //设置点击消失  mNotification.setShowWhen(true); //显示通知时间,貌似不加这句也能显示  mNotification.setTicker("PadInfo"); //弹出通知  mNotification.setSmallIcon(17301620); //设置当前app图标  //mNotification.setDefaults(Notification.DEFAULT_VIBRATE);  //声音、闪灯、震动效果,可叠加,此语句无效  mNotification.setPriority(Notification.PRIORITY_DEFAULT); //通知优先级    mNotification.flags = Notification.FLAG_ONLY_ALERT_ONCE; //发起通知时震动    mNotification.setContentIntent(pendingIntent);var mNb = mNotification.build();//判断当前系统版本在8.0及以上    if (firstVersionNumber >= 8) {nm.notify("s" + NotifyID, NotifyID, mNb);} else {nm.notify(NotifyID, mNb);}//void plus.device.beep(2);//bee bee叫  plus.device.vibrate(300); //震动  console.log('通知结束');return true;// #endif  
}

本文发布于:2024-02-04 14:21:05,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170709215856328.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:模块   消息   功能   push   app
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23