RouterUtil.java
2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.chudiangameplay.android.util;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import com.chudiangameplay.android.MyApplication;
import com.chudiangameplay.android.bean.RouterParamBean;
import com.chudiangameplay.android.tool.CommToast;
import com.chudiangameplay.android.tool.Log;
import com.google.gson.Gson;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Iterator;
/**
* Created by Administrator on 2018/11/27.
*/
public class RouterUtil {
public static void startActivity(Context mContext, String param) {
//
Log.i("param:" + param);
try {
RouterParamBean pushBean = new Gson().fromJson(param, RouterParamBean.class);
String arr[] = pushBean.androidRoute.split("\\?");
//链接
String className = arr[0].replace("/khpw/", "");
//参数
Bundle bundle = new Bundle();
if (arr.length > 1) {
String[] arrParam = arr[1].split("&"); // title=11
for (int i = 0; i < arrParam.length; i++) {
if (!TextUtils.isEmpty(arrParam[i])) {
String[] keyvalue = arrParam[i].split("=");
String key = keyvalue[0];
String value = keyvalue[1];
bundle.putString(key, value);
}
}
// String paramText = arr[1].replace("params=", "");
// try {
// JSONObject jsonObject = new JSONObject(paramText);
//// jsonObject.keys()
// //迭代器用于while循环
// Iterator iter = jsonObject.keys();
// while (iter.hasNext()) {
// String key = (String) iter.next();
// String value = jsonObject.getString(key);
// bundle.putString(key, value);
// }
// } catch (JSONException e) {
// e.printStackTrace();
// }
}
String fullText = MyApplication.context.getPackageName() + ".ui.activity." + className;
Intent intent = new Intent();
intent.setClassName(MyApplication.context.getPackageName(), fullText);
intent.putExtras(bundle);
mContext.startActivity(intent);
} catch (Exception e) {
CommToast.showToast(MyApplication.context, "配置错误");
}
}
}