complete java-update-function java-check-network
Showing
10 changed files
with
251 additions
and
58 deletions
This diff is collapsed.
Click to expand it.
... | @@ -9,6 +9,9 @@ | ... | @@ -9,6 +9,9 @@ |
9 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | 9 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
10 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> | 10 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> |
11 | 11 | ||
12 | <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> | ||
13 | <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> | ||
14 | |||
12 | <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | 15 | <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> |
13 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | 16 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> |
14 | 17 | ||
... | @@ -19,6 +22,10 @@ | ... | @@ -19,6 +22,10 @@ |
19 | <uses-permission android:name="android.permission.WAKE_LOCK" /> | 22 | <uses-permission android:name="android.permission.WAKE_LOCK" /> |
20 | <uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> | 23 | <uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> |
21 | 24 | ||
25 | <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /> | ||
26 | <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> | ||
27 | <uses-permission android:name="com.hiveview.cloudscreen.user.READPROVIDER" /> | ||
28 | <uses-permission android:name="com.hiveview.cloudscreen.user.WRITE_USERINFO_DB"/> | ||
22 | 29 | ||
23 | <application | 30 | <application |
24 | android:allowBackup="true" | 31 | android:allowBackup="true" | ... | ... |
... | @@ -137,4 +137,5 @@ dependencies { | ... | @@ -137,4 +137,5 @@ dependencies { |
137 | implementation fileTree(include: ['*.jar'], dir: 'D:/CocosCreator_2.0.10/resources/cocos2d-x/cocos/platform/android/java/libs') | 137 | implementation fileTree(include: ['*.jar'], dir: 'D:/CocosCreator_2.0.10/resources/cocos2d-x/cocos/platform/android/java/libs') |
138 | implementation project(':libcocos2dx') | 138 | implementation project(':libcocos2dx') |
139 | implementation files('libs/TopdrawSDK.jar') | 139 | implementation files('libs/TopdrawSDK.jar') |
140 | implementation 'com.mcxiaoke.volley:library:+' | ||
140 | } | 141 | } | ... | ... |
1 | [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2,"versionName":"2.0","enabled":true,"outputFile":"super_child-release.apk","fullName":"release","baseName":"release"},"path":"super_child-release.apk","properties":{}}] | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
build/jsb-link/frameworks/runtime-src/proj.android-studio/app/res/layout/softupdate_progress.xml
0 → 100644
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
3 | android:layout_width="match_parent" | ||
4 | android:layout_height="wrap_content"> | ||
5 | |||
6 | <ProgressBar | ||
7 | android:id="@+id/update_progress" | ||
8 | style="?android:attr/progressBarStyleHorizontal" | ||
9 | android:layout_width="fill_parent" | ||
10 | android:layout_height="wrap_content" | ||
11 | android:layout_centerHorizontal="true" /> | ||
12 | |||
13 | <TextView | ||
14 | android:id="@+id/tv_progress" | ||
15 | android:layout_width="wrap_content" | ||
16 | android:layout_height="wrap_content" | ||
17 | android:layout_below="@id/update_progress" | ||
18 | android:layout_alignParentRight="true" | ||
19 | android:layout_margin="5dp" | ||
20 | android:textSize="18sp" | ||
21 | android:text="0%"/> | ||
22 | |||
23 | </RelativeLayout> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -27,31 +27,80 @@ package org.cocos2dx.javascript; | ... | @@ -27,31 +27,80 @@ package org.cocos2dx.javascript; |
27 | import org.cocos2d.helloworld.R; | 27 | import org.cocos2d.helloworld.R; |
28 | import org.cocos2dx.lib.Cocos2dxActivity; | 28 | import org.cocos2dx.lib.Cocos2dxActivity; |
29 | import org.cocos2dx.lib.Cocos2dxGLSurfaceView; | 29 | import org.cocos2dx.lib.Cocos2dxGLSurfaceView; |
30 | import org.json.JSONArray; | ||
31 | import org.json.JSONObject; | ||
30 | 32 | ||
33 | import android.app.AlertDialog; | ||
31 | import android.content.ComponentName; | 34 | import android.content.ComponentName; |
35 | import android.content.Context; | ||
36 | import android.content.DialogInterface; | ||
37 | import android.net.ConnectivityManager; | ||
38 | import android.net.NetworkInfo; | ||
32 | import android.os.Bundle; | 39 | import android.os.Bundle; |
33 | 40 | ||
34 | import android.content.Intent; | 41 | import android.content.Intent; |
35 | import android.content.res.Configuration; | 42 | import android.content.res.Configuration; |
43 | import android.provider.Settings; | ||
36 | import android.util.Log; | 44 | import android.util.Log; |
37 | import android.view.LayoutInflater; | 45 | import android.view.LayoutInflater; |
38 | import android.view.View; | 46 | import android.view.View; |
39 | import android.widget.ProgressBar; | 47 | import android.widget.ProgressBar; |
48 | import android.widget.TextView; | ||
40 | import android.widget.Toast; | 49 | import android.widget.Toast; |
41 | 50 | ||
51 | import com.android.volley.Request; | ||
52 | import com.android.volley.Response; | ||
53 | import com.android.volley.VolleyError; | ||
54 | import com.android.volley.toolbox.JsonObjectRequest; | ||
55 | |||
42 | public class AppActivity extends Cocos2dxActivity { | 56 | public class AppActivity extends Cocos2dxActivity { |
43 | private static final String TAG="AppActivity"; | 57 | private static final String TAG="AppActivity"; |
44 | private static AppActivity _activity; | 58 | private static AppActivity _activity; |
45 | private static View view=null; | 59 | private static View view=null; |
60 | public static final String ROOT_DIR = "/mnt/sdcard/mythroad11"; | ||
61 | private UpdateManager mUpdateManager; | ||
62 | private int serverVersion ; //从服务器获取的版本号 | ||
63 | private int clientVersion ; //客户端当前的版本号 | ||
64 | private String serverVersionName ; //客户端当前的版本名称 | ||
65 | private String apkDownloadUrl ; //apk下载地址 | ||
46 | @Override | 66 | @Override |
47 | protected void onCreate(Bundle savedInstanceState) { | 67 | protected void onCreate(Bundle savedInstanceState) { |
48 | super.onCreate(savedInstanceState); | 68 | super.onCreate(savedInstanceState); |
49 | 69 | ||
70 | Log.d(TAG,"网络链接:"+isNetworkAvalible(AppActivity.this)); | ||
71 | if(!isNetworkAvalible(AppActivity.this)){ | ||
72 | TextView msg = new TextView(AppActivity.this); | ||
73 | msg.setText(" 当前未连接网络,请设置网络后登陆!"); | ||
74 | new AlertDialog.Builder(AppActivity.this) | ||
75 | .setIcon(R.mipmap.ic_launcher) | ||
76 | .setTitle("网络状态提示") | ||
77 | .setView(msg) | ||
78 | .setPositiveButton("确定", | ||
79 | new DialogInterface.OnClickListener() { | ||
80 | public void onClick(DialogInterface dialog, | ||
81 | int whichButton) { | ||
82 | startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); | ||
83 | try { | ||
84 | new Thread().sleep(2000); | ||
85 | } catch (Exception e) { | ||
86 | e.printStackTrace(); | ||
87 | } | ||
88 | AppActivity.this.finish(); | ||
89 | System.exit(0); | ||
90 | android.os.Process.killProcess(android.os.Process.myPid()); | ||
91 | } | ||
92 | }).create().show(); | ||
93 | } | ||
94 | getClientCode(); | ||
95 | getServerCode(); | ||
96 | |||
97 | _activity=this; | ||
98 | TopdrawSDKWrapper.getInstance().init(this); | ||
99 | MyApplication.appActivity = this; | ||
100 | |||
50 | view= LayoutInflater.from(this).inflate(R.layout.activity_main,null); | 101 | view= LayoutInflater.from(this).inflate(R.layout.activity_main,null); |
51 | mFrameLayout.addView(view); | 102 | mFrameLayout.addView(view); |
52 | 103 | ||
53 | // setContentView(R.layout.activity_main); | ||
54 | _activity=this; | ||
55 | // Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508 | 104 | // Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508 |
56 | if (!isTaskRoot()) { | 105 | if (!isTaskRoot()) { |
57 | // Android launched another instance of the root activity into an existing task | 106 | // Android launched another instance of the root activity into an existing task |
... | @@ -61,9 +110,6 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -61,9 +110,6 @@ public class AppActivity extends Cocos2dxActivity { |
61 | return; | 110 | return; |
62 | } | 111 | } |
63 | 112 | ||
64 | TopdrawSDKWrapper.getInstance().init(this); | ||
65 | MyApplication.appActivity = this; | ||
66 | |||
67 | // DO OTHER INITIALIZATION BELOW | 113 | // DO OTHER INITIALIZATION BELOW |
68 | SDKWrapper.getInstance().init(this); | 114 | SDKWrapper.getInstance().init(this); |
69 | } | 115 | } |
... | @@ -158,57 +204,57 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -158,57 +204,57 @@ public class AppActivity extends Cocos2dxActivity { |
158 | public View getProgressBarView(){ | 204 | public View getProgressBarView(){ |
159 | return view; | 205 | return view; |
160 | } | 206 | } |
161 | 207 | private void getClientCode() { | |
162 | public static void startGame(int i,String apkName,final String strJSCallBack){ | 208 | try { |
163 | Log.d(TAG,"AppActivity starGame start..."+apkName); | 209 | String pkName = this.getPackageName(); |
164 | // if (pluginLoaded) { | 210 | clientVersion = this.getPackageManager().getPackageInfo(pkName, 0).versionCode; |
165 | // return; | 211 | } catch (Exception e) { |
166 | // } | 212 | e.printStackTrace(); |
167 | // pluginLoaded = true; | 213 | clientVersion = -1; |
168 | // final String packageName = "com.topdraw.xhx"; | 214 | }finally { |
169 | // final String className = "org.cocos2dx.lua.AppActivity"; | 215 | Log.v("zjn","---clientVersion:"+ clientVersion); |
170 | // PluginLoader.getInstance().start(packageName, new PluginLoader.OnResultListener() { | 216 | } |
171 | // @Override | 217 | } |
172 | // public void onResult(int i, final String msg) { | 218 | private void getServerCode(){ |
173 | // if (0 == i) { | 219 | VolleyUtil.instance(this).add(new JsonObjectRequest(Request.Method.GET, UpdateManager.UPDATE_CHECK_ENDPOINT, "", |
174 | // try { | 220 | new Response.Listener<JSONObject>() { |
175 | // Intent intent = new Intent(); | 221 | @Override |
176 | // intent.setComponent(new ComponentName(packageName, className)); | 222 | public void onResponse(JSONObject response) { |
177 | // intent.putExtra("path", msg); | 223 | try { |
178 | // intent.putExtra("needNewProcess", true); | 224 | JSONArray results = (JSONArray) response.get("resultSet"); |
179 | // intent.putExtra("needHook", true); | 225 | serverVersion = results.getJSONObject(0).getInt("versionCode"); |
180 | // _activity.startActivity(intent); | 226 | serverVersionName = results.getJSONObject(0).getString("versionName"); |
181 | // pluginLoaded = false; | 227 | apkDownloadUrl = results.getJSONObject(0).getString("url"); |
182 | // } catch (Exception e) { | 228 | String md5Str = results.getJSONObject(0).getString("hash_md5"); |
183 | // e.printStackTrace(); | 229 | mUpdateManager = new UpdateManager(AppActivity.this); |
184 | // } | 230 | mUpdateManager.showNoticeDialog(serverVersion,clientVersion,serverVersionName,apkDownloadUrl,md5Str); |
185 | // } else if (-10 == i) { | 231 | } catch (Exception e) { |
186 | // Toast.makeText(_activity, msg, Toast.LENGTH_LONG).show(); | 232 | e.printStackTrace(); |
187 | // pluginLoaded = false; | 233 | } |
188 | // } else { | 234 | } |
189 | // Log.d(TAG, "start plugin error | " + msg); | 235 | }, |
190 | // } | 236 | new Response.ErrorListener() { |
191 | // } | 237 | @Override |
192 | // }, | 238 | public void onErrorResponse(VolleyError error) { |
193 | // new PluginLoader.OnProgressListener() { | ||
194 | // @Override | ||
195 | // public void onProgress(final double d) { | ||
196 | // _activity.runOnUiThread(new Runnable() { | ||
197 | // @Override | ||
198 | // public void run() { | ||
199 | // int pg = Double.valueOf(d).intValue(); | ||
200 | // if (100 == pg) { | ||
201 | // pb_progress.setVisibility(View.INVISIBLE); | ||
202 | // } else { | ||
203 | // if (View.INVISIBLE == pb_progress.getVisibility()) { | ||
204 | // pb_progress.setVisibility(View.VISIBLE); | ||
205 | // } | ||
206 | // } | ||
207 | // pb_progress.setProgress(pg); | ||
208 | // } | ||
209 | // }); | ||
210 | // } | ||
211 | // }); | ||
212 | |||
213 | } | 239 | } |
240 | })); | ||
241 | } | ||
242 | public static boolean isNetworkAvalible(Context context) { | ||
243 | ConnectivityManager connectivityManager = (ConnectivityManager) context | ||
244 | .getSystemService(Context.CONNECTIVITY_SERVICE); | ||
245 | if (connectivityManager == null) { | ||
246 | return false; | ||
247 | } else { | ||
248 | NetworkInfo[] net_info = connectivityManager.getAllNetworkInfo(); | ||
249 | if (net_info != null) { | ||
250 | for (int i = 0; i < net_info.length; i++) { | ||
251 | if (net_info[i].getState() == NetworkInfo.State.CONNECTED) { | ||
252 | return true; | ||
253 | } | ||
254 | } | ||
255 | } | ||
256 | } | ||
257 | return false; | ||
258 | } | ||
259 | |||
214 | } | 260 | } | ... | ... |
This diff is collapsed.
Click to expand it.
1 | package org.cocos2dx.javascript; | ||
2 | |||
3 | import android.content.Context; | ||
4 | import android.util.Log; | ||
5 | |||
6 | import com.android.volley.AuthFailureError; | ||
7 | import com.android.volley.Request; | ||
8 | import com.android.volley.RequestQueue; | ||
9 | import com.android.volley.Response; | ||
10 | import com.android.volley.VolleyError; | ||
11 | import com.android.volley.toolbox.StringRequest; | ||
12 | import com.android.volley.toolbox.Volley; | ||
13 | import com.topdraw.sdk.ITopdrawResultListener; | ||
14 | |||
15 | import java.util.HashMap; | ||
16 | import java.util.Map; | ||
17 | |||
18 | /** | ||
19 | * Created by gyzhong on 15/3/1. | ||
20 | */ | ||
21 | public class VolleyUtil { | ||
22 | String TAG = "chenzhu"; | ||
23 | private static RequestQueue mRequestQueue = null; | ||
24 | static VolleyUtil volleyUtil ; | ||
25 | String s = ""; | ||
26 | boolean isExit = false;//是否继续请求 | ||
27 | public static VolleyUtil getVolley(){ | ||
28 | if (volleyUtil==null){ | ||
29 | volleyUtil = new VolleyUtil(); | ||
30 | } | ||
31 | return volleyUtil; | ||
32 | } | ||
33 | |||
34 | public static RequestQueue instance(Context context) { | ||
35 | if (mRequestQueue == null) { | ||
36 | synchronized (VolleyUtil.class) { | ||
37 | if (mRequestQueue == null) { | ||
38 | mRequestQueue = Volley.newRequestQueue(context); | ||
39 | mRequestQueue.start(); | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | return mRequestQueue; | ||
44 | } | ||
45 | |||
46 | public boolean getIsExit(){ | ||
47 | return isExit; | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * @author chenzhu | ||
52 | * creat at 2017/9/1 15:52 | ||
53 | * @parms | ||
54 | * @return 请求后的回掉 | ||
55 | **/ | ||
56 | public interface PostCallBack { | ||
57 | void postSuccess(int flag, String jsonObject); | ||
58 | void postFaile(int flag,String error); | ||
59 | } | ||
60 | |||
61 | public void setIsExit(boolean exit){ | ||
62 | isExit = exit; | ||
63 | } | ||
64 | |||
65 | |||
66 | |||
67 | /** | ||
68 | *@author chenzhu | ||
69 | *creat at 2017/9/1 16:01 | ||
70 | *@param CallBack 请求的回调 | ||
71 | * @param parm 请求回调的flag | ||
72 | * @param map 请求回调的参数 | ||
73 | *@param url 请求的url | ||
74 | *@return | ||
75 | *post qingqiu | ||
76 | **/ | ||
77 | public void volleypost(Context context, final PostCallBack CallBack, final int parm,final String url, final HashMap map) { | ||
78 | Log.i("chenzhu", "chenzhu--->post请求成功:--->isExit"+isExit); | ||
79 | if(isExit){ | ||
80 | return; | ||
81 | } | ||
82 | StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { | ||
83 | @Override | ||
84 | public void onResponse(String s) { | ||
85 | Log.i("chenzhu", "chenzhu--->post请求成功:--->parm:"+parm+"token:"+map.get("token") +"jsonObject:"+s+"--->URL:"+url+"--appID:"+map.get("appId")+"--songIds:"+map.get("songIds")); | ||
86 | CallBack.postSuccess(parm,s); | ||
87 | } | ||
88 | }, new Response.ErrorListener() { | ||
89 | @Override | ||
90 | public void onErrorResponse(VolleyError volleyError) { | ||
91 | Log.i("chenzhu", "chenzhu--->post请求失败" + volleyError+"--->parm"+parm+"--->URL:"+url); | ||
92 | CallBack.postFaile(parm,volleyError+""); | ||
93 | } | ||
94 | }) { | ||
95 | @Override | ||
96 | protected Map<String, String> getParams() throws AuthFailureError { | ||
97 | |||
98 | return map; | ||
99 | } | ||
100 | }; | ||
101 | VolleyUtil.instance(context).add(request); | ||
102 | } | ||
103 | |||
104 | /** | ||
105 | *@author chenzhu | ||
106 | *creat at 2017/9/1 21:23 | ||
107 | *@parms | ||
108 | *@return | ||
109 | *停止请求 | ||
110 | **/ | ||
111 | public void stopPost(Context context){ | ||
112 | // VolleyUtil.instance(context).cancelAll(null); | ||
113 | } | ||
114 | |||
115 | } |
... | @@ -251,7 +251,6 @@ | ... | @@ -251,7 +251,6 @@ |
251 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_split_apk_resources" /> | 251 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_split_apk_resources" /> |
252 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javac" /> | 252 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javac" /> |
253 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" /> | 253 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" /> |
254 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint_jar" /> | ||
255 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifest-checker" /> | 254 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifest-checker" /> |
256 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged-not-compiled-resources" /> | 255 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged-not-compiled-resources" /> |
257 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_assets" /> | 256 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_assets" /> |
... | @@ -280,6 +279,7 @@ | ... | @@ -280,6 +279,7 @@ |
280 | <orderEntry type="library" name="Gradle: __local_aars__:D.\LocalTopdrawSchool\build\jsb-link\frameworks\runtime-src\proj.android-studio\app\libs\TopdrawSDK.jar:unspecified@jar" level="project" /> | 279 | <orderEntry type="library" name="Gradle: __local_aars__:D.\LocalTopdrawSchool\build\jsb-link\frameworks\runtime-src\proj.android-studio\app\libs\TopdrawSDK.jar:unspecified@jar" level="project" /> |
281 | <orderEntry type="library" name="Gradle: __local_aars__:D.\CocosCreator_2.0.10\resources\cocos2d-x\cocos\platform\android\java\libs\com.android.vending.expansion.zipfile.jar:unspecified@jar" level="project" /> | 280 | <orderEntry type="library" name="Gradle: __local_aars__:D.\CocosCreator_2.0.10\resources\cocos2d-x\cocos\platform\android\java\libs\com.android.vending.expansion.zipfile.jar:unspecified@jar" level="project" /> |
282 | <orderEntry type="library" name="Gradle: __local_aars__:D.\CocosCreator_2.0.10\resources\cocos2d-x\cocos\platform\android\java\libs\android-async-http-1.4.9.jar:unspecified@jar" level="project" /> | 281 | <orderEntry type="library" name="Gradle: __local_aars__:D.\CocosCreator_2.0.10\resources\cocos2d-x\cocos\platform\android\java\libs\android-async-http-1.4.9.jar:unspecified@jar" level="project" /> |
282 | <orderEntry type="library" name="Gradle: com.mcxiaoke.volley:library:1.0.19@jar" level="project" /> | ||
283 | <orderEntry type="module" module-name="libcocos2dx" /> | 283 | <orderEntry type="module" module-name="libcocos2dx" /> |
284 | </component> | 284 | </component> |
285 | </module> | 285 | </module> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment