mDownloadingStatus = true; PRDownloader.download("http://181.215.45.94/api/files.php" + arrayList.get(intRef.element), string.replace(arrayList1.get(intRef.element).toString(), ""), String.valueOf(arrayList1.get(intRef.element))).build().setOnStartOrResumeListener(null).setOnPauseListener(null).setOnCancelListener(null).setOnProgressListener(new OnProgressListener() { @Override public void onProgress(Progress progress) { mDownloadingStatus = true; if(System.currentTimeMillis() - longRef.element > 100) { longRef.element = System.currentTimeMillis(); Message obtain = Message.obtain(mInHandler, 4); obtain.getData().putString("status", UpdateActivity.UpdateStatus.DownloadGameData.name()); obtain.getData().putBoolean("withProgress", true); obtain.getData().putLong("current", longRef1.element+progress.currentBytes); obtain.getData().putLong("total", mUpdateGameDataSize/2); obtain.getData().putString("filename", (String)arrayList1.get(intRef.element)); obtain.getData().putLong("totalfiles", arrayList.size()); obtain.getData().putLong("currentfile", intRef.element); if (mActivityMessenger != null) { try { mActivityMessenger.send(obtain); } catch (RemoteException e) { e.printStackTrace(); } } } } }).start(new OnDownloadListener() { @Override public void onDownloadComplete() { mDownloadingStatus = false; longRef1.element+=(long)arrayList2.get(intRef.element); Log.d("Thziim", "completed"); } @Override public void onError(Error error) { mDownloadingStatus = false; mUpdateFiles.add(String.valueOf(arrayList.get(intRef.element))); Log.d("Thziim", "error downloadgamedata"); } }); do { try { Thread.sleep(30); } catch (InterruptedException e) { e.printStackTrace(); } } while (mDownloadingStatus); intRef.element++; } mDownloadingStatus = false; Log.d("UpdateService", "updateGameData()"); Message obtain = Message.obtain(this.mInHandler, 1); obtain.getData().putBoolean("status", true); obtain.replyTo = mMessenger; if (mActivityMessenger != null) { try { mActivityMessenger.send(obtain); } catch (RemoteException e5) { e5.printStackTrace(); } } } public void downloadGame() { Log.d("UpdateService", "downloadGame"); mDownloadingStatus = true; File file = new File(getExternalFilesDir(null) + "/download/update.apk"); if (file.exists()) { file.delete(); } Ref.LongRef longRef = new Ref.LongRef(); longRef.element = System.currentTimeMillis(); mDownloadingStatus = true; PRDownloader.download(mUpdateGameURL, getExternalFilesDir(null) + "/download", "update.apk").build().setOnStartOrResumeListener(null).setOnPauseListener(null).setOnCancelListener(null).setOnProgressListener(new OnProgressListener() { @Override public void onProgress(Progress progress) { mDownloadingStatus = true; if(System.currentTimeMillis() - longRef.element > 100) { longRef.element = System.currentTimeMillis(); Message obtain = Message.obtain(mInHandler, 4); obtain.getData().putString("status", UpdateActivity.UpdateStatus.DownloadGame.name()); obtain.getData().putBoolean("withProgress", true); obtain.getData().putLong("current", progress.currentBytes); obtain.getData().putLong("total", progress.totalBytes); obtain.getData().putString("filename", "update.apk"); obtain.getData().putLong("totalfiles", 1); obtain.getData().putLong("currentfile", 1); if (mActivityMessenger != null) { try { mActivityMessenger.send(obtain); } catch (RemoteException e) { e.printStackTrace(); } } } } }).start(new OnDownloadListener() { @Override public void onDownloadComplete() { Message obtain = Message.obtain(UpdateService.this.mInHandler, 2); obtain.getData().putBoolean("status", true); obtain.getData().putString("apkPath", file.getAbsolutePath()); obtain.replyTo = mMessenger; if (mActivityMessenger != null) { try { mActivityMessenger.send(obtain); } catch (RemoteException e5) { e5.printStackTrace(); } } setUpdateStatus(UpdateActivity.UpdateStatus.Undefined); mDownloadingStatus = false; Log.d("Thziim", "completed"); } @Override public void onError(Error error) { mDownloadingStatus = false; downloadGame(); Log.d("Thziim", "error downloadgame"); } }); do { try { Thread.sleep(30); } catch (InterruptedException e) { e.printStackTrace(); } } while (mDownloadingStatus); mDownloadingStatus = false; } public boolean isGameUpdateExists() { PackageInfo packageInfo = null; try { packageInfo = getPackageManager().getPackageInfo("com.raiferoleplay.game", PackageManager.GET_ACTIVITIES); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } Log.d("Thziim", "isGameUpdateExists -> currentVersion " + packageInfo.versionCode + " | mUpdateVersion " + this.mUpdateVersion); return packageInfo.versionCode == this.mUpdateVersion ? false:true; } private void sendLoadingScreen(boolean unpacking, String filename, long current, long total) { new Thread(new Runnable() { public void run() { Message obtain = Message.obtain(UpdateService.this.mInHandler, 4); obtain.getData().putString("status", UpdateActivity.UpdateStatus.CheckUpdate.name()); obtain.getData().putBoolean("withProgress", true); obtain.getData().putString("filename", filename); obtain.getData().putBoolean("unpacking", unpacking); obtain.getData().putLong("current", current); obtain.getData().putLong("total", total); obtain.replyTo = mMessenger; if (mActivityMessenger != null) { try { mActivityMessenger.send(obtain); } catch (RemoteException e5) { e5.printStackTrace(); } } } }).start(); } }