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 . 在适当的位置调用--

重点5+HTML方法(官方查询api): plus.push.createMessage(content, payload, options);
		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);  
                            }  
                        }  
                    });  
                }
            },

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM