推送消息跳转

This commit is contained in:
huangzhuanghua
2016-12-26 15:31:21 +08:00
parent be4fc50ae0
commit f2500aeb6e
23 changed files with 176 additions and 88 deletions

View File

@ -0,0 +1,71 @@
package com.gh.base;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import com.gh.common.util.ClassUtils;
import com.gh.common.util.RunningUtils;
import com.gh.gamecenter.SplashScreenActivity;
import com.umeng.message.UmengNotificationClickHandler;
import com.umeng.message.entity.UMessage;
import org.json.JSONException;
import org.json.JSONObject;
public class GHUmengNotificationClickHandler extends UmengNotificationClickHandler {
@Override
public void launchApp(Context context, UMessage uMessage) {
super.launchApp(context, uMessage);
String content = uMessage.extra.get("data");
try {
JSONObject response = new JSONObject(content);
Bundle bundle = new Bundle();
bundle.putString("entrance", "(友盟推送)");
String type = response.getString("type");
if ("article".equals(type)) {
bundle.putString("to", "NewsDetailActivity");
bundle.putString("newsId", response.getString("target"));
} else if ("game".equals(type)) {
bundle.putString("to", "GameDetailActivity");
bundle.putString("gameId", response.getString("target"));
} else if ("column".equals(type)) {
bundle.putString("to", "SubjectActivity");
bundle.putString("id", response.getString("target"));
} else if ("web".equals(type)) {
bundle.putString("to", "WebActivity");
bundle.putString("url", response.getString("target"));
}
if (RunningUtils.isRunning(context)) {
// 应用正在运行,前台或后台
String to = bundle.getString("to");
if (!TextUtils.isEmpty(to)) {
Class<?> clazz = ClassUtils.forName(to);
if (clazz != null) {
Intent intent1 = new Intent(context, clazz);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.putExtra("data", bundle);
context.startActivity(intent1);
}
}
} else {
// 应用未在运行
Intent intent1 = new Intent(context, SplashScreenActivity.class);
intent1.setAction(Intent.ACTION_MAIN);
intent1.addCategory(Intent.CATEGORY_LAUNCHER);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.putExtra("data", bundle);
context.startActivity(intent1);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}