uni-app 不介入第三方,本地调用手机通知栏

配置:

1. 勾选push

 

2. 配置manifest.json

 

"app-plus" : {
"modules" : {
"Push" : {
"igexin" : {
"appid" : "123456",  // 随便填写
"appkey" : "123456",   // 随便填写
"appsecret" : "123456"  // 随便填写
}
}
},

 

/* ios打包配置 */
"sdkConfigs" : {
"ad" : {},
"push" : {
"igexin" : {
"appid" : "123456",
"appkey" : "123456",
"appsecret" : "123456"
}
}
},

 

3 . 在适当的位置调用--

1
重点5+HTML方法(官方查询api):  plus.push.createMessage(content, payload, options);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
androidNoticeBar(data) {
        /* 安卓通知栏提醒显示 */
        var content = "您有一条新的消息!";
        var options = {
            "cover" : false, // 覆盖上次
            "when" : new Date(),
            'title' : "通知消息"
        };
         
        var body = {
          'id' : 'id',
          'key2': "key2"
        }
        var payload = JSON.stringify(body);
        plus.push.createMessage(content, payload, options);
        /* end */
    }

  4. 是否开启通知权限--如果没有,跳转设置开启

复制代码
            tongzhiPerssiom(){
                var main = plus.android.runtimeMainActivity();  
                var pkName = main.getPackageName();  
                var NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat");  
                var packageNames = NotificationManagerCompat.from(main);  
                if (packageNames.areNotificationsEnabled()) {  
                    console.log('已开启通知权限');  
                }else{  
                    uni.showModal({  
                        title: '通知权限开启提醒',  
                        content: '您还没有开启通知权限,无法接收到消息通知,是否前往设置',  
                        showCancel: false,  
                        success: function (res) {  
                            if (res.confirm) {  
                                var Intent = plus.android.importClass('android.content.Intent');  
                                var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');//可设置表中所有Action字段  
                                intent.putExtra('android.provider.extra.APP_PACKAGE', pkName);  
                                main.startActivity(intent);  
                            }  
                        }  
                    });  
                }
            },
复制代码

 

posted @   小白咚  阅读(2487)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示