1.解决下载游戏时返回,游戏依然在后台下载
Showing
4 changed files
with
73 additions
and
14 deletions
| ... | @@ -353,9 +353,9 @@ cc.Class({ | ... | @@ -353,9 +353,9 @@ cc.Class({ |
| 353 | } | 353 | } |
| 354 | this._aFocusTargets[0]['ButtonOpen'] = cc.find('ButtonOpen', this.node); | 354 | this._aFocusTargets[0]['ButtonOpen'] = cc.find('ButtonOpen', this.node); |
| 355 | 355 | ||
| 356 | let fiBanner = cc.find('ButtonVip', this.node).addComponent(FocusInfo); // | 356 | // let fiBanner = cc.find('ButtonVip', this.node).addComponent(FocusInfo); // |
| 357 | fiBanner.init('', true, null, null, 1.06); | 357 | // fiBanner.init('', true, null, null, 1.06); |
| 358 | this._aFocusTargets[0]['button_vip'] = cc.find('ButtonVip', this.node); | 358 | // this._aFocusTargets[0]['button_vip'] = cc.find('ButtonVip', this.node); |
| 359 | 359 | ||
| 360 | var nodeInitFocus = cc.find('ButtonOpen', this.node); //强制写死,不然会闪屏,找不到ButtonOpen | 360 | var nodeInitFocus = cc.find('ButtonOpen', this.node); //强制写死,不然会闪屏,找不到ButtonOpen |
| 361 | // cc.log("初始化 " + nodeInitFocus.name); | 361 | // cc.log("初始化 " + nodeInitFocus.name); | ... | ... |
| ... | @@ -100,6 +100,9 @@ cc.Class({ | ... | @@ -100,6 +100,9 @@ cc.Class({ |
| 100 | case cc.macro.KEY.backspace: | 100 | case cc.macro.KEY.backspace: |
| 101 | case Common.ANDROID_KEY.back: | 101 | case Common.ANDROID_KEY.back: |
| 102 | this._bIsFocusInit = true; | 102 | this._bIsFocusInit = true; |
| 103 | if (this._oSceneContext._downloadUrl && this._oSceneContext._downloadUrl != "undefined") { //如果有下载地址就启动奥比游戏 | ||
| 104 | jsb.reflection.callStaticMethod("com/topdraw/melody/TopdrawSDKWrapper", "closeDownloadObiApk", "()V"); | ||
| 105 | } | ||
| 103 | this.backAScene(); | 106 | this.backAScene(); |
| 104 | break; | 107 | break; |
| 105 | } | 108 | } | ... | ... |
| ... | @@ -37,6 +37,11 @@ public class OBiPluginLoader { | ... | @@ -37,6 +37,11 @@ public class OBiPluginLoader { |
| 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 HttpURLConnection conn; | ||
| 41 | private BufferedInputStream bis = null; | ||
| 42 | private FileOutputStream fos = null; | ||
| 43 | private File fTemp; | ||
| 44 | private File dirPackage; | ||
| 40 | 45 | ||
| 41 | public static OBiPluginLoader getInstance() { | 46 | public static OBiPluginLoader getInstance() { |
| 42 | if (null == instance) { | 47 | if (null == instance) { |
| ... | @@ -83,10 +88,7 @@ public class OBiPluginLoader { | ... | @@ -83,10 +88,7 @@ public class OBiPluginLoader { |
| 83 | 88 | ||
| 84 | public void start(String downloadUrl, String packageName, final OnResultListener rListener, final OnProgressListener pListener) { | 89 | public void start(String downloadUrl, String packageName, final OnResultListener rListener, final OnProgressListener pListener) { |
| 85 | this.path = downloadUrl; | 90 | this.path = downloadUrl; |
| 86 | final File dirPackage = new File(sdPath + packageName); | 91 | dirPackage = new File(sdPath + packageName); |
| 87 | if (!dirPackage.exists()) { | ||
| 88 | dirPackage.mkdir(); | ||
| 89 | Log.d("OBiPluginLoader", "创建目录" + dirPackage); | ||
| 90 | final OnProgressListener pl = new OnProgressListener() { | 92 | final OnProgressListener pl = new OnProgressListener() { |
| 91 | @Override | 93 | @Override |
| 92 | public void onProgress(double d) { | 94 | public void onProgress(double d) { |
| ... | @@ -95,7 +97,6 @@ public class OBiPluginLoader { | ... | @@ -95,7 +97,6 @@ public class OBiPluginLoader { |
| 95 | } | 97 | } |
| 96 | } | 98 | } |
| 97 | }; | 99 | }; |
| 98 | |||
| 99 | String fileName = null; | 100 | String fileName = null; |
| 100 | if (null != this.path) { | 101 | if (null != this.path) { |
| 101 | if (this.path.contains("?")) { | 102 | if (this.path.contains("?")) { |
| ... | @@ -107,6 +108,9 @@ public class OBiPluginLoader { | ... | @@ -107,6 +108,9 @@ public class OBiPluginLoader { |
| 107 | fileName = this.path.substring(this.path.lastIndexOf("/") + 1); | 108 | fileName = this.path.substring(this.path.lastIndexOf("/") + 1); |
| 108 | } | 109 | } |
| 109 | } | 110 | } |
| 111 | if (!dirPackage.exists()) { | ||
| 112 | dirPackage.mkdir(); | ||
| 113 | Log.d("OBiPluginLoader", "创建目录" + dirPackage); | ||
| 110 | final File fileTempOK = new File(dirPackage, fileName); | 114 | final File fileTempOK = new File(dirPackage, fileName); |
| 111 | final OnResultListener rl = new OnResultListener() { | 115 | final OnResultListener rl = new OnResultListener() { |
| 112 | @Override | 116 | @Override |
| ... | @@ -152,6 +156,27 @@ public class OBiPluginLoader { | ... | @@ -152,6 +156,27 @@ public class OBiPluginLoader { |
| 152 | if (null != rListener) { | 156 | if (null != rListener) { |
| 153 | rListener.onResult(0, path); | 157 | rListener.onResult(0, path); |
| 154 | } | 158 | } |
| 159 | } else { //这里再去下载,jerry -0317 | ||
| 160 | final File fileTempOK = new File(dirPackage, fileName); | ||
| 161 | final OnResultListener rl = new OnResultListener() { | ||
| 162 | @Override | ||
| 163 | public void onResult(int i, String msg) { | ||
| 164 | if (0 == i) { | ||
| 165 | boolean checkSuccess = false; | ||
| 166 | if (fileTempOK.exists() && fileTempOK.isFile()) { | ||
| 167 | if (null != rListener) { | ||
| 168 | rListener.onResult(0, fileTempOK.getAbsolutePath()); | ||
| 169 | } | ||
| 170 | } | ||
| 171 | } | ||
| 172 | } | ||
| 173 | }; | ||
| 174 | new Thread(new Runnable() { | ||
| 175 | @Override | ||
| 176 | public void run() { | ||
| 177 | downloadApk("", fileTempOK, rl, pl); | ||
| 178 | } | ||
| 179 | }).start(); | ||
| 155 | } | 180 | } |
| 156 | } | 181 | } |
| 157 | } | 182 | } |
| ... | @@ -159,8 +184,6 @@ public class OBiPluginLoader { | ... | @@ -159,8 +184,6 @@ public class OBiPluginLoader { |
| 159 | public void downloadApk(String downloadURL, final File file, OnResultListener rlistener, OnProgressListener plistener) { | 184 | public void downloadApk(String downloadURL, final File file, OnResultListener rlistener, OnProgressListener plistener) { |
| 160 | Log.d("OBiPluginLoader", "downloadApk start.."); | 185 | Log.d("OBiPluginLoader", "downloadApk start.."); |
| 161 | downloadURL = this.path; | 186 | downloadURL = this.path; |
| 162 | BufferedInputStream bis = null; | ||
| 163 | FileOutputStream fos = null; | ||
| 164 | try { | 187 | try { |
| 165 | if (file.exists() && file.isFile()) { | 188 | if (file.exists() && file.isFile()) { |
| 166 | file.delete(); | 189 | file.delete(); |
| ... | @@ -169,7 +192,7 @@ public class OBiPluginLoader { | ... | @@ -169,7 +192,7 @@ public class OBiPluginLoader { |
| 169 | if (!parentFile.exists()) { | 192 | if (!parentFile.exists()) { |
| 170 | parentFile.mkdir(); | 193 | parentFile.mkdir(); |
| 171 | } | 194 | } |
| 172 | File f = new File(file.getAbsolutePath() + "_temp"); | 195 | fTemp = new File(file.getAbsolutePath() + "_temp"); |
| 173 | String url = null; | 196 | String url = null; |
| 174 | if (downloadURL.startsWith("http")) { | 197 | if (downloadURL.startsWith("http")) { |
| 175 | url = downloadURL; | 198 | url = downloadURL; |
| ... | @@ -178,7 +201,7 @@ public class OBiPluginLoader { | ... | @@ -178,7 +201,7 @@ public class OBiPluginLoader { |
| 178 | } | 201 | } |
| 179 | URL u = new URL(url); | 202 | URL u = new URL(url); |
| 180 | Log.d("OBiPluginLoader", "downloadAPK url: " + url); | 203 | Log.d("OBiPluginLoader", "downloadAPK url: " + url); |
| 181 | HttpURLConnection conn = (HttpURLConnection) u.openConnection(); | 204 | conn = (HttpURLConnection) u.openConnection(); |
| 182 | conn.setRequestMethod("GET"); | 205 | conn.setRequestMethod("GET"); |
| 183 | conn.setConnectTimeout(5000); | 206 | conn.setConnectTimeout(5000); |
| 184 | conn.setReadTimeout(5000); | 207 | conn.setReadTimeout(5000); |
| ... | @@ -199,7 +222,7 @@ public class OBiPluginLoader { | ... | @@ -199,7 +222,7 @@ public class OBiPluginLoader { |
| 199 | long tempReadSize = 0; | 222 | long tempReadSize = 0; |
| 200 | long progressSize = 0; | 223 | long progressSize = 0; |
| 201 | bis = new BufferedInputStream(conn.getInputStream()); | 224 | bis = new BufferedInputStream(conn.getInputStream()); |
| 202 | fos = new FileOutputStream(f); | 225 | fos = new FileOutputStream(fTemp); |
| 203 | byte[] buffer = new byte[1024]; | 226 | byte[] buffer = new byte[1024]; |
| 204 | int len = 0; | 227 | int len = 0; |
| 205 | while ((len = bis.read(buffer)) != -1) { | 228 | while ((len = bis.read(buffer)) != -1) { |
| ... | @@ -228,7 +251,7 @@ public class OBiPluginLoader { | ... | @@ -228,7 +251,7 @@ public class OBiPluginLoader { |
| 228 | } | 251 | } |
| 229 | fos.write(buffer, 0, len); | 252 | fos.write(buffer, 0, len); |
| 230 | } | 253 | } |
| 231 | boolean flag = f.renameTo(file); | 254 | boolean flag = fTemp.renameTo(file); |
| 232 | String[] command = {"chmod", "777", file.getPath()}; | 255 | String[] command = {"chmod", "777", file.getPath()}; |
| 233 | ProcessBuilder builder = new ProcessBuilder(command); | 256 | ProcessBuilder builder = new ProcessBuilder(command); |
| 234 | try { | 257 | try { |
| ... | @@ -272,6 +295,34 @@ public class OBiPluginLoader { | ... | @@ -272,6 +295,34 @@ public class OBiPluginLoader { |
| 272 | } | 295 | } |
| 273 | } | 296 | } |
| 274 | 297 | ||
| 298 | public void closeDownloadApk() { | ||
| 299 | Log.d("OBiPluginLoader", "目录是否存在:" + dirPackage.exists()); | ||
| 300 | if (fTemp.exists() && fTemp.isFile()) { | ||
| 301 | fTemp.delete(); | ||
| 302 | } | ||
| 303 | if (null != conn) { | ||
| 304 | try { | ||
| 305 | conn.disconnect(); | ||
| 306 | } catch (Exception e) { | ||
| 307 | e.printStackTrace(); | ||
| 308 | } | ||
| 309 | } | ||
| 310 | if (null != bis) { | ||
| 311 | try { | ||
| 312 | bis.close(); | ||
| 313 | } catch (IOException e) { | ||
| 314 | e.printStackTrace(); | ||
| 315 | } | ||
| 316 | } | ||
| 317 | if (null != fos) { | ||
| 318 | try { | ||
| 319 | fos.close(); | ||
| 320 | } catch (IOException e) { | ||
| 321 | e.printStackTrace(); | ||
| 322 | } | ||
| 323 | } | ||
| 324 | } | ||
| 325 | |||
| 275 | public interface OnResultListener { | 326 | public interface OnResultListener { |
| 276 | public void onResult(int i, String msg); | 327 | public void onResult(int i, String msg); |
| 277 | } | 328 | } | ... | ... |
| ... | @@ -321,6 +321,11 @@ public class TopdrawSDKWrapper { | ... | @@ -321,6 +321,11 @@ public class TopdrawSDKWrapper { |
| 321 | }); | 321 | }); |
| 322 | } | 322 | } |
| 323 | 323 | ||
| 324 | public static void closeDownloadObiApk() { | ||
| 325 | Log.d(TAG,"取消下载。。。"); | ||
| 326 | OBiPluginLoader.getInstance().closeDownloadApk(); | ||
| 327 | } | ||
| 328 | |||
| 324 | public static boolean isApkInstalled(Context context, String packageName) { | 329 | public static boolean isApkInstalled(Context context, String packageName) { |
| 325 | // List<PackageInfo> packageInfoList = context.getPackageManager().getInstalledPackages(0); | 330 | // List<PackageInfo> packageInfoList = context.getPackageManager().getInstalledPackages(0); |
| 326 | // for (int i = 0; i < packageInfoList.size(); i++) { | 331 | // for (int i = 0; i < packageInfoList.size(); i++) { | ... | ... |
-
Please register or sign in to post a comment