Skip to content

Commit

Permalink
app stability toward updates
Browse files Browse the repository at this point in the history
  • Loading branch information
zeseeit committed Dec 3, 2016
1 parent 5159440 commit c16cdaf
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
Binary file modified app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "any.audio"
minSdkVersion 17
targetSdkVersion 24
versionCode 3
versionName "0.0.3"
versionCode 4
versionName "0.0.4"
generatedDensities = []

}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="4"
android:versionName="0.0.4"
package="any.audio" >

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/any/audio/Updates/version
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version":4,
"newInThisUpdate":"v0.0.3-alpha testing \n bug fixations \n Stability",
"appDownloadUrl":"https://github.com/zeseeit/AnyAudio/releases/download/v0.0.4-alpha/anyaudio.apk"
"newInThisUpdate":"v0.0.4-alpha \n Better UI \n Greater Stability",
"appDownloadUrl":"https://github.com/zeseeit/AnyAudio/releases/download/v0.0.4/anyaudio_build_20161203_3.apk"
}
36 changes: 25 additions & 11 deletions app/src/main/java/any/audio/services/UpdateCheckService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Handler;
Expand Down Expand Up @@ -35,8 +37,8 @@
*/
public class UpdateCheckService extends Service {

// private static final long CHECK_UPDATE_INTERVAL = 6 * 60 * 60 * 1000; // 6 hrs interval
private static final long CHECK_UPDATE_INTERVAL = 20 * 1000; // 20 sec interval
private static final long CHECK_UPDATE_INTERVAL = 6 * 60 * 60 * 1000; // 6 hrs interval
//private static final long CHECK_UPDATE_INTERVAL = 20 * 1000; // 20 sec interval
private static final int SERVER_TIMEOUT_LIMIT = 10 * 1000; // 10 sec
private static Timer mTimer;
Handler mHandler = new Handler();
Expand Down Expand Up @@ -64,8 +66,6 @@ public void onCreate() {
private void checkForUpdate() {

Log.d("UpdateServiceAnyAudio", " UpdateCheck....");


StringRequest updateCheckReq = new StringRequest(
Request.Method.GET,
url,
Expand Down Expand Up @@ -104,17 +104,35 @@ public boolean isForeground(String myPackage) {

ActivityManager mActivityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
String mpackageName = "";

if (Build.VERSION.SDK_INT > 20) {

mpackageName = String.valueOf(mActivityManager.getRunningAppProcesses().get(0).processName);

} else {

mpackageName = String.valueOf(mActivityManager.getRunningTasks(1).get(0).topActivity.getClassName());

}

L.m("UpdateService", "found " + mpackageName);
return mpackageName.equals(myPackage);

}

private int getCurrentAppVersionCode() {
return SharedPrefrenceUtils.getInstance(getApplicationContext()).getCurrentVersionCode();

try {

PackageInfo _info = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
return _info.versionCode;

} catch (PackageManager.NameNotFoundException e) {

e.printStackTrace();
return -1;

}
}

public void handleNewUpdateResponse(String response) {
Expand All @@ -130,12 +148,12 @@ public void handleNewUpdateResponse(String response) {
* */

try {
JSONObject updateResp = new JSONObject(response);

JSONObject updateResp = new JSONObject(response);
double newVersion = updateResp.getDouble("version");
String updateDescription = updateResp.getString("newInThisUpdate");
String downloadUrl = updateResp.getString("appDownloadUrl");
Log.d("UpdateServiceTest"," new Version "+newVersion+" old version "+getCurrentAppVersionCode()+" update Des "+updateDescription);
Log.d("UpdateServiceTest", " new Version " + newVersion + " old version " + getCurrentAppVersionCode() + " update Des " + updateDescription);

if (newVersion > getCurrentAppVersionCode()) {
// write update to shared pref..
Expand All @@ -149,9 +167,5 @@ public void handleNewUpdateResponse(String response) {
} catch (JSONException e) {
e.printStackTrace();
}


}


}

0 comments on commit c16cdaf

Please sign in to comment.