cordova与android通信_Cordova与原生安卓互相调用(混合app开发)

//MessageReceiver方法,继承XGPushBaseReceiver

// 通知点击回调 actionType=1为该消息被清除,actionType=0为该消息被点击。此处不能做点击消息跳转,详细方法请参照官网的Android常见问题文档

@Override

public void onNotifactionClickedResult(Context context,

XGPushClickedResult message) {

// Log.e("LC", "+++++++++++++++ 通知被点击 跳转到指定页面。");

NotificationManager notificationManager = (NotificationManager) context

.getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.cancelAll();

if (context == null || message == null) {

return;

}

if (message.getActionType() == XGPushClickedResult.NOTIFACTION_CLICKED_TYPE) {

// 通知在通知栏被点击啦。。。。。

// APP自己处理点击的相关动作

// 这个动作可以在activity的onResume也能监听,请看第3点相关内容

Intent intent = null;

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

String customContent = message.getCustomContent();

intent.putExtra("customContent",customContent);

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

context.startActivity(intent);

} else if (message.getActionType() == XGPushClickedResult.NOTIFACTION_DELETED_TYPE) {

// 通知被清除啦。。。。

// APP自己处理通知被清除后的相关动作

}

// 获取自定义key-value

String customContent = message.getCustomContent();

if (customContent != null && customContent.length() != 0) {

try {

JSONObject obj = new JSONObject(customContent);

// key1为前台配置的key

if (!obj.isNull("message_id")) {

String value = obj.getString("message_id");

// Log.d(LogTag, "get custom value message_id:" + value);

}

if (!obj.isNull("message_cat")) {

String value = obj.getString("message_cat");

// Log.d(LogTag, "get custom value message_cat:" + value);

}

} catch (JSONException e) {

// Log.d(LogTag,e.getMessage());

}

}

}

//MainActivity方法

@Override

protected void onNewIntent(Intent intent) {

super.onNewIntent(intent);

getIntentData(intent);

}

private void getIntentData(Intent intent) {

if(intent!=null){

Bundle extras = intent.getExtras();

if(extras != null){

Object customContent = extras.get("customContent");

if(customContent != null){

loadUrl("javascript:toInfo("+customContent+")");

}

}

}

}

//js方法

function toInfo(customContent) {

console.log(customContent);

if(customContent.infoType == "1" || customContent.infoType == "2" || customContent.infoType == "4"){

var deviceid = customContent.deviceid;

var lat = customContent.lat;

var lon = customContent.lon;

var time = customContent.time;

location.href = "file:///android_asset/www/index.html#/location?deviceid="+deviceid+"&lat="+lat+"&lon="+lon+"&time="+time+"&flag=2";

}else if(customContent.infoType = "5"){

location.href = "file:///android_asset/www/index.html#/sysInfo";

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值