1.解决安装包解析错误和卸载apk不能清理残留数据的问题
2.新增网络判断
Showing
6 changed files
with
145 additions
and
10 deletions
... | @@ -192,7 +192,7 @@ | ... | @@ -192,7 +192,7 @@ |
192 | "array": [ | 192 | "array": [ |
193 | 0, | 193 | 0, |
194 | 0, | 194 | 0, |
195 | 271.060302734375, | 195 | 271.0606994628906, |
196 | 0, | 196 | 0, |
197 | 0, | 197 | 0, |
198 | 0, | 198 | 0, |
... | @@ -5376,8 +5376,8 @@ | ... | @@ -5376,8 +5376,8 @@ |
5376 | } | 5376 | } |
5377 | ], | 5377 | ], |
5378 | "_useOriginalSize": false, | 5378 | "_useOriginalSize": false, |
5379 | "_string": "v1.0.0.2020031717", | 5379 | "_string": "v1.0.0.2020033017", |
5380 | "_N$string": "v1.0.0.2020031717", | 5380 | "_N$string": "v1.0.0.2020033017", |
5381 | "_fontSize": 24, | 5381 | "_fontSize": 24, |
5382 | "_lineHeight": 24, | 5382 | "_lineHeight": 24, |
5383 | "_enableWrapText": true, | 5383 | "_enableWrapText": true, | ... | ... |
1 | package com.topdraw.melody; | ||
2 | |||
3 | import android.content.Context; | ||
4 | import android.content.pm.PackageInfo; | ||
5 | import android.content.pm.PackageManager; | ||
6 | import android.net.ConnectivityManager; | ||
7 | import android.net.NetworkInfo; | ||
8 | import android.text.TextUtils; | ||
9 | |||
10 | import java.io.File; | ||
11 | |||
12 | /** | ||
13 | * author : Jinwawa | ||
14 | * date : 2020/3/30 0030. | ||
15 | * desc : 自定义工具类 | ||
16 | */ | ||
17 | public class CommonUtils { | ||
18 | |||
19 | public static boolean checkAppInstalled(Context context, String pkgName) { | ||
20 | if (pkgName == null || pkgName.isEmpty()) { | ||
21 | return false; | ||
22 | } | ||
23 | PackageInfo packageInfo; | ||
24 | try { | ||
25 | packageInfo = context.getPackageManager().getPackageInfo(pkgName, 0); | ||
26 | } catch (PackageManager.NameNotFoundException e) { | ||
27 | packageInfo = null; | ||
28 | e.printStackTrace(); | ||
29 | } | ||
30 | if (packageInfo == null) { | ||
31 | return false; | ||
32 | } else { | ||
33 | return true;//true为安装了,false为未安装 | ||
34 | } | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | * 删除指定目录下的文件及目录 | ||
39 | */ | ||
40 | public static void deleteFolderFile(String filePath, boolean deleteThisPath) { | ||
41 | if (!TextUtils.isEmpty(filePath)) { | ||
42 | File file = new File(filePath); | ||
43 | if (file.isDirectory()) { | ||
44 | File files[] = file.listFiles(); | ||
45 | for (int i = 0; i < files.length; i++) { | ||
46 | deleteFolderFile(files[i].getAbsolutePath(), true); | ||
47 | } | ||
48 | } | ||
49 | if (deleteThisPath) { | ||
50 | if (!file.isDirectory()) { | ||
51 | file.delete(); | ||
52 | } else { | ||
53 | if (file.listFiles().length == 0) { | ||
54 | file.delete(); | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | |||
61 | public static boolean isNetworkAvalible(Context context) { | ||
62 | ConnectivityManager connectivityManager = (ConnectivityManager) context | ||
63 | .getSystemService(Context.CONNECTIVITY_SERVICE); | ||
64 | if (connectivityManager == null) { | ||
65 | return false; | ||
66 | } else { | ||
67 | NetworkInfo[] net_info = connectivityManager.getAllNetworkInfo(); | ||
68 | if (net_info != null) { | ||
69 | for (int i = 0; i < net_info.length; i++) { | ||
70 | if (net_info[i].getState() == NetworkInfo.State.CONNECTED) { | ||
71 | return true; | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | return false; | ||
77 | } | ||
78 | } |
... | @@ -24,7 +24,8 @@ public class MelodyApplication extends TopdrawApplication { | ... | @@ -24,7 +24,8 @@ public class MelodyApplication extends TopdrawApplication { |
24 | public static AppActivity appActivity; | 24 | public static AppActivity appActivity; |
25 | public static boolean authResult = false; | 25 | public static boolean authResult = false; |
26 | private static MelodyApplication app; | 26 | private static MelodyApplication app; |
27 | public static String TOPDRAW_API_PATH = "http://139.196.4.234:38080/hyperion.chimera";;; | 27 | public static String TOPDRAW_API_PATH = "http://139.196.4.234:38080/hyperion.chimera"; |
28 | ;; | ||
28 | private Handler mHandler = new Handler(); | 29 | private Handler mHandler = new Handler(); |
29 | 30 | ||
30 | @Override | 31 | @Override |
... | @@ -40,6 +41,8 @@ public class MelodyApplication extends TopdrawApplication { | ... | @@ -40,6 +41,8 @@ public class MelodyApplication extends TopdrawApplication { |
40 | PluginLoader.getInstance().init(getApplicationContext(), mHandler, TOPDRAW_API_PATH, "/plugin/plugin.json"); | 41 | PluginLoader.getInstance().init(getApplicationContext(), mHandler, TOPDRAW_API_PATH, "/plugin/plugin.json"); |
41 | PluginLoader.getInstance().start(); | 42 | PluginLoader.getInstance().start(); |
42 | 43 | ||
44 | OBiPluginLoader.getInstance().init(getApplicationContext()); | ||
45 | |||
43 | //CrashHandler crashHandler = CrashHandler.getInstance(); | 46 | //CrashHandler crashHandler = CrashHandler.getInstance(); |
44 | //crashHandler.setCustomCrashHanler(getApplicationContext()); | 47 | //crashHandler.setCustomCrashHanler(getApplicationContext()); |
45 | //MobclickAgent.UMAnalyticsConfig kk = new MobclickAgent.UMAnalyticsConfig(this,"5a168338a40fa377b500012b","amt"); | 48 | //MobclickAgent.UMAnalyticsConfig kk = new MobclickAgent.UMAnalyticsConfig(this,"5a168338a40fa377b500012b","amt"); | ... | ... |
... | @@ -30,18 +30,20 @@ public class OBiPluginLoader { | ... | @@ -30,18 +30,20 @@ public class OBiPluginLoader { |
30 | 30 | ||
31 | private static OBiPluginLoader instance; | 31 | private static OBiPluginLoader instance; |
32 | private String server; | 32 | private String server; |
33 | private String path = "http://topdraw-game.oss-cn-shanghai.aliyuncs.com/forfun/XhxAndroid_bird_shdx.apk"; | 33 | private String path = ""; |
34 | 34 | ||
35 | public static final int PROGRESS_1 = 100; | 35 | public static final int PROGRESS_1 = 100; |
36 | public static final int PROGRESS_0_1 = 10; | 36 | public static final int PROGRESS_0_1 = 10; |
37 | public static final int PROGRESS_0_01 = 1; | 37 | public static final int PROGRESS_0_01 = 1; |
38 | public static double PROGRESS = PROGRESS_1; | 38 | public static double PROGRESS = PROGRESS_1; |
39 | private String sdPath = Environment.getExternalStorageDirectory() + "/"; | 39 | // private String sdPath = Environment.getExternalStorageDirectory() + "/"; |
40 | private File sdPath; | ||
40 | private HttpURLConnection conn; | 41 | private HttpURLConnection conn; |
41 | private BufferedInputStream bis = null; | 42 | private BufferedInputStream bis = null; |
42 | private FileOutputStream fos = null; | 43 | private FileOutputStream fos = null; |
43 | private File fTemp; | 44 | private File fTemp; |
44 | private File dirPackage; | 45 | private File dirPackage; |
46 | private Context context; | ||
45 | 47 | ||
46 | public static OBiPluginLoader getInstance() { | 48 | public static OBiPluginLoader getInstance() { |
47 | if (null == instance) { | 49 | if (null == instance) { |
... | @@ -50,6 +52,11 @@ public class OBiPluginLoader { | ... | @@ -50,6 +52,11 @@ public class OBiPluginLoader { |
50 | return instance; | 52 | return instance; |
51 | } | 53 | } |
52 | 54 | ||
55 | public void init(Context context) { | ||
56 | this.context = context; | ||
57 | sdPath = context.getExternalCacheDir().getParentFile(); //用这个路径完美解决了解析错误和卸载应用不能删除残留数据的问题 | ||
58 | } | ||
59 | |||
53 | /** | 60 | /** |
54 | * 判断是否有APK | 61 | * 判断是否有APK |
55 | * | 62 | * |
... | @@ -57,7 +64,7 @@ public class OBiPluginLoader { | ... | @@ -57,7 +64,7 @@ public class OBiPluginLoader { |
57 | * @return | 64 | * @return |
58 | */ | 65 | */ |
59 | public boolean isExistApk(String packageName) { | 66 | public boolean isExistApk(String packageName) { |
60 | final File dirPackage = new File(sdPath + packageName); | 67 | final File dirPackage = new File(sdPath, packageName); |
61 | if (dirPackage.exists()) { | 68 | if (dirPackage.exists()) { |
62 | String path = null; | 69 | String path = null; |
63 | File[] files = dirPackage.listFiles(); | 70 | File[] files = dirPackage.listFiles(); |
... | @@ -88,7 +95,7 @@ public class OBiPluginLoader { | ... | @@ -88,7 +95,7 @@ public class OBiPluginLoader { |
88 | 95 | ||
89 | public void start(String downloadUrl, String packageName, final OnResultListener rListener, final OnProgressListener pListener) { | 96 | public void start(String downloadUrl, String packageName, final OnResultListener rListener, final OnProgressListener pListener) { |
90 | this.path = downloadUrl; | 97 | this.path = downloadUrl; |
91 | dirPackage = new File(sdPath + packageName); | 98 | dirPackage = new File(sdPath, packageName); |
92 | final OnProgressListener pl = new OnProgressListener() { | 99 | final OnProgressListener pl = new OnProgressListener() { |
93 | @Override | 100 | @Override |
94 | public void onProgress(double d) { | 101 | public void onProgress(double d) { | ... | ... |
... | @@ -21,6 +21,7 @@ import com.topdraw.forfun.R; | ... | @@ -21,6 +21,7 @@ import com.topdraw.forfun.R; |
21 | import com.topdraw.sdk.*; | 21 | import com.topdraw.sdk.*; |
22 | 22 | ||
23 | import java.io.File; | 23 | import java.io.File; |
24 | import java.io.IOException; | ||
24 | import java.util.*; | 25 | import java.util.*; |
25 | 26 | ||
26 | import org.cocos2dx.javascript.AppActivity; | 27 | import org.cocos2dx.javascript.AppActivity; |
... | @@ -322,7 +323,7 @@ public class TopdrawSDKWrapper { | ... | @@ -322,7 +323,7 @@ public class TopdrawSDKWrapper { |
322 | } | 323 | } |
323 | 324 | ||
324 | public static void closeDownloadObiApk() { | 325 | public static void closeDownloadObiApk() { |
325 | Log.d(TAG,"取消下载。。。"); | 326 | Log.d(TAG, "取消下载。。。"); |
326 | OBiPluginLoader.getInstance().closeDownloadApk(); | 327 | OBiPluginLoader.getInstance().closeDownloadApk(); |
327 | } | 328 | } |
328 | 329 | ||
... | @@ -353,6 +354,15 @@ public class TopdrawSDKWrapper { | ... | @@ -353,6 +354,15 @@ public class TopdrawSDKWrapper { |
353 | */ | 354 | */ |
354 | public static void startInstall(Context context, String path) { | 355 | public static void startInstall(Context context, String path) { |
355 | Log.d(TAG, "安装的包路径。。。" + path); | 356 | Log.d(TAG, "安装的包路径。。。" + path); |
357 | |||
358 | //修改安装包权限 | ||
359 | // String cmd="chmod 777 "+path; | ||
360 | // try { | ||
361 | // Runtime.getRuntime().exec(cmd); | ||
362 | // } catch (IOException e) { | ||
363 | // e.printStackTrace(); | ||
364 | // } | ||
365 | |||
356 | Intent install = new Intent(Intent.ACTION_VIEW); | 366 | Intent install = new Intent(Intent.ACTION_VIEW); |
357 | install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 367 | install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
358 | install.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive"); | 368 | install.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive"); | ... | ... |
... | @@ -28,14 +28,18 @@ import org.cocos2dx.lib.Cocos2dxActivity; | ... | @@ -28,14 +28,18 @@ import org.cocos2dx.lib.Cocos2dxActivity; |
28 | import org.cocos2dx.lib.Cocos2dxGLSurfaceView; | 28 | import org.cocos2dx.lib.Cocos2dxGLSurfaceView; |
29 | import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge; | 29 | import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge; |
30 | 30 | ||
31 | import android.app.AlertDialog; | ||
31 | import android.content.BroadcastReceiver; | 32 | import android.content.BroadcastReceiver; |
32 | import android.content.Context; | 33 | import android.content.Context; |
34 | import android.content.DialogInterface; | ||
33 | import android.content.IntentFilter; | 35 | import android.content.IntentFilter; |
34 | import android.os.Bundle; | 36 | import android.os.Bundle; |
35 | 37 | ||
36 | import android.content.Intent; | 38 | import android.content.Intent; |
37 | import android.content.res.Configuration; | 39 | import android.content.res.Configuration; |
40 | import android.os.Environment; | ||
38 | import android.os.Handler; | 41 | import android.os.Handler; |
42 | import android.provider.Settings; | ||
39 | import android.util.Log; | 43 | import android.util.Log; |
40 | import android.view.KeyEvent; | 44 | import android.view.KeyEvent; |
41 | import android.view.LayoutInflater; | 45 | import android.view.LayoutInflater; |
... | @@ -47,9 +51,11 @@ import android.widget.FrameLayout; | ... | @@ -47,9 +51,11 @@ import android.widget.FrameLayout; |
47 | import android.widget.ImageView; | 51 | import android.widget.ImageView; |
48 | import android.widget.LinearLayout; | 52 | import android.widget.LinearLayout; |
49 | import android.widget.RelativeLayout; | 53 | import android.widget.RelativeLayout; |
54 | import android.widget.TextView; | ||
50 | 55 | ||
51 | import com.topdraw.component.CocosMediaPlayer; | 56 | import com.topdraw.component.CocosMediaPlayer; |
52 | import com.topdraw.forfun.R; | 57 | import com.topdraw.forfun.R; |
58 | import com.topdraw.melody.CommonUtils; | ||
53 | import com.topdraw.melody.MelodyApplication; | 59 | import com.topdraw.melody.MelodyApplication; |
54 | import com.topdraw.melody.TopdrawSDKWrapper; | 60 | import com.topdraw.melody.TopdrawSDKWrapper; |
55 | 61 | ||
... | @@ -68,6 +74,10 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -68,6 +74,10 @@ public class AppActivity extends Cocos2dxActivity { |
68 | @Override | 74 | @Override |
69 | protected void onCreate(Bundle savedInstanceState) { | 75 | protected void onCreate(Bundle savedInstanceState) { |
70 | super.onCreate(savedInstanceState); | 76 | super.onCreate(savedInstanceState); |
77 | Log.d(TAG, "判断APK是否安装。。。" + getExternalCacheDir().getPath()); | ||
78 | |||
79 | checkNetwork(); //检查网络 | ||
80 | |||
71 | //----解决游戏页按返回退出时,背景图透明度过高,onPause和onResume中控制显示还是隐藏 | 81 | //----解决游戏页按返回退出时,背景图透明度过高,onPause和onResume中控制显示还是隐藏 |
72 | singleView = LayoutInflater.from(this).inflate(R.layout.activity_main_single_color, null); | 82 | singleView = LayoutInflater.from(this).inflate(R.layout.activity_main_single_color, null); |
73 | mRLSingleColor = singleView.findViewById(R.id.ll_single); | 83 | mRLSingleColor = singleView.findViewById(R.id.ll_single); |
... | @@ -160,7 +170,6 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -160,7 +170,6 @@ public class AppActivity extends Cocos2dxActivity { |
160 | // setTheme(android.R.style.Theme_NoDisplay); | 170 | // setTheme(android.R.style.Theme_NoDisplay); |
161 | super.onPause(); | 171 | super.onPause(); |
162 | SDKWrapper.getInstance().onPause(); | 172 | SDKWrapper.getInstance().onPause(); |
163 | |||
164 | } | 173 | } |
165 | 174 | ||
166 | @Override | 175 | @Override |
... | @@ -248,6 +257,34 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -248,6 +257,34 @@ public class AppActivity extends Cocos2dxActivity { |
248 | }); | 257 | }); |
249 | } | 258 | } |
250 | 259 | ||
260 | //检查网络 | ||
261 | private void checkNetwork() { | ||
262 | Log.d(TAG, "网络链接:" + CommonUtils.isNetworkAvalible(AppActivity.this)); | ||
263 | if (!CommonUtils.isNetworkAvalible(AppActivity.this)) { | ||
264 | TextView msg = new TextView(AppActivity.this); | ||
265 | msg.setText(" 当前未连接网络,请设置网络后登陆!"); | ||
266 | new AlertDialog.Builder(AppActivity.this) | ||
267 | .setIcon(R.mipmap.ic_launcher) | ||
268 | .setTitle("网络状态提示") | ||
269 | .setView(msg) | ||
270 | .setPositiveButton("确定", | ||
271 | new DialogInterface.OnClickListener() { | ||
272 | public void onClick(DialogInterface dialog, | ||
273 | int whichButton) { | ||
274 | startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); | ||
275 | try { | ||
276 | new Thread().sleep(2000); | ||
277 | } catch (Exception e) { | ||
278 | e.printStackTrace(); | ||
279 | } | ||
280 | AppActivity.this.finish(); | ||
281 | System.exit(0); | ||
282 | android.os.Process.killProcess(android.os.Process.myPid()); | ||
283 | } | ||
284 | }).create().show(); | ||
285 | } | ||
286 | } | ||
287 | |||
251 | public View getProgressBarView() { | 288 | public View getProgressBarView() { |
252 | return view; | 289 | return view; |
253 | } | 290 | } | ... | ... |
-
Please register or sign in to post a comment