//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";
}
}