android系统信息推送

博客介绍了判断是否启动App而非刷新界面执行方法,给出系统信息推送主要代码,可设置显示内容、图标等,在华为手机测试有效。还提到按手机版本大小用plus.android.importClass(name)方法导入类对象,作用不大,并展示了效果图。

1、判断是否是启动App,而非刷新界面执行该方法

if (!window.name) {
    window.name = 'test';
    InfoPush(data.data.length)
}

2、系统信息推送主要代码,设置所要显示的内容、图标等信息,在华为手机上测试有效,其它手机并不清楚效果如何

//系统信息推送
function InfoPush(len) {
	if (plus.os.name == 'Android') {
		//当前版本号  
		var SystemVersion = plus.os.version;  
		var Context = plus.android.importClass("android.content.Context");  
		var main = plus.android.runtimeMainActivity();  
		var NotificationManager = plus.android.importClass("android.app.NotificationManager");  
		var nm = main.getSystemService(Context.NOTIFICATION_SERVICE)  
		// Notification build 要android api16以上才能使用(4.1.2以上)  
		var Notification = null;
		if (compareVersion('4.1.1', SystemVersion) == true) {  
			Notification = plus.android.importClass("android.app.Notification");  
		} else {  
			Notification = plus.android.importClass("android.support.v4.app.NotificationCompat");  
		}  
		if (Notification) {  
			var NotifyID = 1;  
			var mNotification = new Notification.Builder(main);  
			var Intent = plus.android.importClass("android.content.Intent");  
			var PendingIntent = plus.android.importClass("android.app.PendingIntent");  
			var intent = new Intent(main, main.getClass());
			var pendingIntent = PendingIntent.getActivity(main, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);  
			var r = plus.android.importClass("android.R");  

			// mNotification.setOngoing(true);  //是否固定
			mNotification.setContentTitle("ZZApp")  
			mNotification.setContentText("你有" + len + "新信息")  
			mNotification.setSmallIcon(r.drawable.ic_notification_overlay)  
			mNotification.setTicker("ZZApp")  

			mNotification.setContentIntent(pendingIntent);  //点击后转跳			
			mNotification.setAutoCancel(true)//点击后删除
			
			var mNb = mNotification.build()  
			nm.notify(NotifyID, mNb);  
		}  
	}
}

 

3、比较按照手机的版本大小,通过plus.android.importClass(name)方法导入相关的类对象,并无太大的作用

/**  
 * 比较两个版本大小  
 * 比较版本大小,如果新版本nowVersion大于旧版本OldResourceVersion则返回true,否则返回false  
 */  
function compareVersion(OldVersion, nowVersion) {  
	if (!OldVersion || !nowVersion || OldVersion == '' || nowVersion == '') {  

		return false;  
	}  
	//第二份参数 是 数组的最大长度  
	var OldVersionA = OldVersion.split(".", 4);  
	var nowVersionA = nowVersion.split(".", 4);  
	for (var i = 0; i < OldVersionA.length && i < nowVersionA.length; i++) {  
		var strOld = OldVersionA[i];  
		var numOld = parseInt(strOld);  
		var strNow = nowVersionA[i];  
		var numNow = parseInt(strNow);  
		//小版本到高版本  
		if (numNow > numOld  
			//||strNow.length>strOld.length  
		) {  
			return true;  
		} else if (numNow < numOld) {  
			return false;  
		}  
	}  
	//如果是版本  如 1.6 - 1.6.1  
	if (nowVersionA.length > OldVersionA.length && 0 == nowVersion.indexOf(OldVersion)) {  
		return true;  
	}  
};  

 

效果图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值