Apk downloading and installing successful, but the version still the same. How could that be?
up vote
0
down vote
favorite
I have created an android app, which checks for updates after user logs in.
I have a table in database which contains the apk version name, version code, and release date to parse the apk current version on client.
If I change the versionname and versioncode in build.gradle and upload the new apk to the server I also change the version information in the table.
The problem is, although it looks like its working fine (install screen pops and got a message of successful installation) the application does not update itself.
The versioncode and versionname still remains the same as before, and I am in an endless loop of downloading and updating the same application again and again with no change of current app.
What am I doing wrong?
Here are the codes of interest:
In MainActivity the checkversion method:
private void checkversion(){
PackageInfo packageInfo = null;
try {
packageInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Error occured identifiing the container package of this application.");
}
final TextView tvloadingbar = dialog.getDialog().findViewById(R.id.tvLoadingBar);
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Checking version...");
}
});
final String version = packageInfo.versionName;
final int versioncode = packageInfo.versionCode;
Log.w(TAG, String.format("Checking the versions, actual versionname: %s, actual versioncode: %d", version, versioncode));
Log.w(TAG, "Parsing the server...");
//Query the version from database
ClientAPI.setRequest(new Request.Builder().url(ClientAPI.getBaseurl() + "mobilepackage/versioninfo").build());
try {
Response response = ClientAPI.getClient().newCall(ClientAPI.getRequest()).execute();
if(response.isSuccessful()){
String result = response.body().string();
try {
JSONObject object = new JSONObject(result);
String serverversion = object.getString("Version_Name");
int serverversioncode = object.getInt("Version_Code");
Log.w(TAG, String.format("Got a response from server, versionname: %s, versioncode: %d ", serverversion, serverversioncode));
if(serverversion!=null && serverversioncode!=0){
//check if version codes matched, if true, do nothing
//else download the apk and install it.
if(serverversion.equals(version) && serverversioncode==versioncode){
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Nincs szükség frissítésre");
}
});
Log.w(TAG,"Server versions matched.");
return;
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Update needed");
}
});
Log.w(TAG, "Update needed.");
downloadapk(tvloadingbar);
}
} else {
Log.w(TAG, "No apk to deploy.");
return;
}
} catch (JSONException e) {
Log.w(TAG, "Error occured parsing the JSON Object of versions.");
}
} else {
Log.w(TAG,"Could not determine the version codes. Server response unsuccessful.");
}
} catch (IOException e) {
Log.w(TAG, "Error occured query the version info");
}
}
Heres the downloadapk method
private void downloadapk(final TextView tvloadingbar){
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Downloading new version...");
}
});
// synchronous okhttp call
ClientAPI.setRequest(new Request.Builder().url(ClientAPI.getBaseurl()+ "Mobile_Distro/app-debug.apk").build());
try {
Response response = ClientAPI.getClient().newCall(ClientAPI.getRequest()).execute();
InputStream is = response.body().byteStream();
File file = new File(getExternalFilesDir(null) + File.separator + "app-debug.apk");
BufferedInputStream bis = new BufferedInputStream(is);
OutputStream output = new FileOutputStream(file);
final int SIZE = 10485760;
byte data = new byte[SIZE];
long total = 0;
int count;
while ((count = bis.read(data)) != -1){
total += count;
output.write(data, 0, count);
Log.w("WROTE", String.format("%d bytes",total));
}
Log.w(TAG, String.format("Download successful. Downloaded: %d bytes", total));
output.flush();
output.close();
bis.close();
installapk(tvloadingbar, file);
} catch (IOException e) {
Log.w(TAG,String.format("Downloading new version failed. Details: n %s",e.getMessage()));
}
}
And the method from which apk installs (or look like it installs)
private void installapk(File file){
Log.w(TAG, "Installing new version...");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
I tried this on several phones, none of them indicates errors, but none of them installs the new version. I really don't have a clue what is going on here. Tried touching open after installation, close and launch the application, no use, the app exists as the old version.
Any suggestions?
android installation apk updates
add a comment |
up vote
0
down vote
favorite
I have created an android app, which checks for updates after user logs in.
I have a table in database which contains the apk version name, version code, and release date to parse the apk current version on client.
If I change the versionname and versioncode in build.gradle and upload the new apk to the server I also change the version information in the table.
The problem is, although it looks like its working fine (install screen pops and got a message of successful installation) the application does not update itself.
The versioncode and versionname still remains the same as before, and I am in an endless loop of downloading and updating the same application again and again with no change of current app.
What am I doing wrong?
Here are the codes of interest:
In MainActivity the checkversion method:
private void checkversion(){
PackageInfo packageInfo = null;
try {
packageInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Error occured identifiing the container package of this application.");
}
final TextView tvloadingbar = dialog.getDialog().findViewById(R.id.tvLoadingBar);
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Checking version...");
}
});
final String version = packageInfo.versionName;
final int versioncode = packageInfo.versionCode;
Log.w(TAG, String.format("Checking the versions, actual versionname: %s, actual versioncode: %d", version, versioncode));
Log.w(TAG, "Parsing the server...");
//Query the version from database
ClientAPI.setRequest(new Request.Builder().url(ClientAPI.getBaseurl() + "mobilepackage/versioninfo").build());
try {
Response response = ClientAPI.getClient().newCall(ClientAPI.getRequest()).execute();
if(response.isSuccessful()){
String result = response.body().string();
try {
JSONObject object = new JSONObject(result);
String serverversion = object.getString("Version_Name");
int serverversioncode = object.getInt("Version_Code");
Log.w(TAG, String.format("Got a response from server, versionname: %s, versioncode: %d ", serverversion, serverversioncode));
if(serverversion!=null && serverversioncode!=0){
//check if version codes matched, if true, do nothing
//else download the apk and install it.
if(serverversion.equals(version) && serverversioncode==versioncode){
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Nincs szükség frissítésre");
}
});
Log.w(TAG,"Server versions matched.");
return;
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Update needed");
}
});
Log.w(TAG, "Update needed.");
downloadapk(tvloadingbar);
}
} else {
Log.w(TAG, "No apk to deploy.");
return;
}
} catch (JSONException e) {
Log.w(TAG, "Error occured parsing the JSON Object of versions.");
}
} else {
Log.w(TAG,"Could not determine the version codes. Server response unsuccessful.");
}
} catch (IOException e) {
Log.w(TAG, "Error occured query the version info");
}
}
Heres the downloadapk method
private void downloadapk(final TextView tvloadingbar){
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Downloading new version...");
}
});
// synchronous okhttp call
ClientAPI.setRequest(new Request.Builder().url(ClientAPI.getBaseurl()+ "Mobile_Distro/app-debug.apk").build());
try {
Response response = ClientAPI.getClient().newCall(ClientAPI.getRequest()).execute();
InputStream is = response.body().byteStream();
File file = new File(getExternalFilesDir(null) + File.separator + "app-debug.apk");
BufferedInputStream bis = new BufferedInputStream(is);
OutputStream output = new FileOutputStream(file);
final int SIZE = 10485760;
byte data = new byte[SIZE];
long total = 0;
int count;
while ((count = bis.read(data)) != -1){
total += count;
output.write(data, 0, count);
Log.w("WROTE", String.format("%d bytes",total));
}
Log.w(TAG, String.format("Download successful. Downloaded: %d bytes", total));
output.flush();
output.close();
bis.close();
installapk(tvloadingbar, file);
} catch (IOException e) {
Log.w(TAG,String.format("Downloading new version failed. Details: n %s",e.getMessage()));
}
}
And the method from which apk installs (or look like it installs)
private void installapk(File file){
Log.w(TAG, "Installing new version...");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
I tried this on several phones, none of them indicates errors, but none of them installs the new version. I really don't have a clue what is going on here. Tried touching open after installation, close and launch the application, no use, the app exists as the old version.
Any suggestions?
android installation apk updates
3
are you really sure that the data on your web API equals the version name/version code of the latest app version?
– Vladyslav Matviienko
yesterday
I checked and its not. Thanks for the answer, that was the problem. The web api gave increased versioncode compared to real apk versioncode. Now everything is fine. Sorry everyone, that was a silly question with a terrible easy solution. :(
– Newbie1001
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have created an android app, which checks for updates after user logs in.
I have a table in database which contains the apk version name, version code, and release date to parse the apk current version on client.
If I change the versionname and versioncode in build.gradle and upload the new apk to the server I also change the version information in the table.
The problem is, although it looks like its working fine (install screen pops and got a message of successful installation) the application does not update itself.
The versioncode and versionname still remains the same as before, and I am in an endless loop of downloading and updating the same application again and again with no change of current app.
What am I doing wrong?
Here are the codes of interest:
In MainActivity the checkversion method:
private void checkversion(){
PackageInfo packageInfo = null;
try {
packageInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Error occured identifiing the container package of this application.");
}
final TextView tvloadingbar = dialog.getDialog().findViewById(R.id.tvLoadingBar);
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Checking version...");
}
});
final String version = packageInfo.versionName;
final int versioncode = packageInfo.versionCode;
Log.w(TAG, String.format("Checking the versions, actual versionname: %s, actual versioncode: %d", version, versioncode));
Log.w(TAG, "Parsing the server...");
//Query the version from database
ClientAPI.setRequest(new Request.Builder().url(ClientAPI.getBaseurl() + "mobilepackage/versioninfo").build());
try {
Response response = ClientAPI.getClient().newCall(ClientAPI.getRequest()).execute();
if(response.isSuccessful()){
String result = response.body().string();
try {
JSONObject object = new JSONObject(result);
String serverversion = object.getString("Version_Name");
int serverversioncode = object.getInt("Version_Code");
Log.w(TAG, String.format("Got a response from server, versionname: %s, versioncode: %d ", serverversion, serverversioncode));
if(serverversion!=null && serverversioncode!=0){
//check if version codes matched, if true, do nothing
//else download the apk and install it.
if(serverversion.equals(version) && serverversioncode==versioncode){
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Nincs szükség frissítésre");
}
});
Log.w(TAG,"Server versions matched.");
return;
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Update needed");
}
});
Log.w(TAG, "Update needed.");
downloadapk(tvloadingbar);
}
} else {
Log.w(TAG, "No apk to deploy.");
return;
}
} catch (JSONException e) {
Log.w(TAG, "Error occured parsing the JSON Object of versions.");
}
} else {
Log.w(TAG,"Could not determine the version codes. Server response unsuccessful.");
}
} catch (IOException e) {
Log.w(TAG, "Error occured query the version info");
}
}
Heres the downloadapk method
private void downloadapk(final TextView tvloadingbar){
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Downloading new version...");
}
});
// synchronous okhttp call
ClientAPI.setRequest(new Request.Builder().url(ClientAPI.getBaseurl()+ "Mobile_Distro/app-debug.apk").build());
try {
Response response = ClientAPI.getClient().newCall(ClientAPI.getRequest()).execute();
InputStream is = response.body().byteStream();
File file = new File(getExternalFilesDir(null) + File.separator + "app-debug.apk");
BufferedInputStream bis = new BufferedInputStream(is);
OutputStream output = new FileOutputStream(file);
final int SIZE = 10485760;
byte data = new byte[SIZE];
long total = 0;
int count;
while ((count = bis.read(data)) != -1){
total += count;
output.write(data, 0, count);
Log.w("WROTE", String.format("%d bytes",total));
}
Log.w(TAG, String.format("Download successful. Downloaded: %d bytes", total));
output.flush();
output.close();
bis.close();
installapk(tvloadingbar, file);
} catch (IOException e) {
Log.w(TAG,String.format("Downloading new version failed. Details: n %s",e.getMessage()));
}
}
And the method from which apk installs (or look like it installs)
private void installapk(File file){
Log.w(TAG, "Installing new version...");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
I tried this on several phones, none of them indicates errors, but none of them installs the new version. I really don't have a clue what is going on here. Tried touching open after installation, close and launch the application, no use, the app exists as the old version.
Any suggestions?
android installation apk updates
I have created an android app, which checks for updates after user logs in.
I have a table in database which contains the apk version name, version code, and release date to parse the apk current version on client.
If I change the versionname and versioncode in build.gradle and upload the new apk to the server I also change the version information in the table.
The problem is, although it looks like its working fine (install screen pops and got a message of successful installation) the application does not update itself.
The versioncode and versionname still remains the same as before, and I am in an endless loop of downloading and updating the same application again and again with no change of current app.
What am I doing wrong?
Here are the codes of interest:
In MainActivity the checkversion method:
private void checkversion(){
PackageInfo packageInfo = null;
try {
packageInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Error occured identifiing the container package of this application.");
}
final TextView tvloadingbar = dialog.getDialog().findViewById(R.id.tvLoadingBar);
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Checking version...");
}
});
final String version = packageInfo.versionName;
final int versioncode = packageInfo.versionCode;
Log.w(TAG, String.format("Checking the versions, actual versionname: %s, actual versioncode: %d", version, versioncode));
Log.w(TAG, "Parsing the server...");
//Query the version from database
ClientAPI.setRequest(new Request.Builder().url(ClientAPI.getBaseurl() + "mobilepackage/versioninfo").build());
try {
Response response = ClientAPI.getClient().newCall(ClientAPI.getRequest()).execute();
if(response.isSuccessful()){
String result = response.body().string();
try {
JSONObject object = new JSONObject(result);
String serverversion = object.getString("Version_Name");
int serverversioncode = object.getInt("Version_Code");
Log.w(TAG, String.format("Got a response from server, versionname: %s, versioncode: %d ", serverversion, serverversioncode));
if(serverversion!=null && serverversioncode!=0){
//check if version codes matched, if true, do nothing
//else download the apk and install it.
if(serverversion.equals(version) && serverversioncode==versioncode){
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Nincs szükség frissítésre");
}
});
Log.w(TAG,"Server versions matched.");
return;
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Update needed");
}
});
Log.w(TAG, "Update needed.");
downloadapk(tvloadingbar);
}
} else {
Log.w(TAG, "No apk to deploy.");
return;
}
} catch (JSONException e) {
Log.w(TAG, "Error occured parsing the JSON Object of versions.");
}
} else {
Log.w(TAG,"Could not determine the version codes. Server response unsuccessful.");
}
} catch (IOException e) {
Log.w(TAG, "Error occured query the version info");
}
}
Heres the downloadapk method
private void downloadapk(final TextView tvloadingbar){
runOnUiThread(new Runnable() {
@Override
public void run() {
tvloadingbar.setText("Downloading new version...");
}
});
// synchronous okhttp call
ClientAPI.setRequest(new Request.Builder().url(ClientAPI.getBaseurl()+ "Mobile_Distro/app-debug.apk").build());
try {
Response response = ClientAPI.getClient().newCall(ClientAPI.getRequest()).execute();
InputStream is = response.body().byteStream();
File file = new File(getExternalFilesDir(null) + File.separator + "app-debug.apk");
BufferedInputStream bis = new BufferedInputStream(is);
OutputStream output = new FileOutputStream(file);
final int SIZE = 10485760;
byte data = new byte[SIZE];
long total = 0;
int count;
while ((count = bis.read(data)) != -1){
total += count;
output.write(data, 0, count);
Log.w("WROTE", String.format("%d bytes",total));
}
Log.w(TAG, String.format("Download successful. Downloaded: %d bytes", total));
output.flush();
output.close();
bis.close();
installapk(tvloadingbar, file);
} catch (IOException e) {
Log.w(TAG,String.format("Downloading new version failed. Details: n %s",e.getMessage()));
}
}
And the method from which apk installs (or look like it installs)
private void installapk(File file){
Log.w(TAG, "Installing new version...");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
I tried this on several phones, none of them indicates errors, but none of them installs the new version. I really don't have a clue what is going on here. Tried touching open after installation, close and launch the application, no use, the app exists as the old version.
Any suggestions?
android installation apk updates
android installation apk updates
asked yesterday
Newbie1001
227
227
3
are you really sure that the data on your web API equals the version name/version code of the latest app version?
– Vladyslav Matviienko
yesterday
I checked and its not. Thanks for the answer, that was the problem. The web api gave increased versioncode compared to real apk versioncode. Now everything is fine. Sorry everyone, that was a silly question with a terrible easy solution. :(
– Newbie1001
yesterday
add a comment |
3
are you really sure that the data on your web API equals the version name/version code of the latest app version?
– Vladyslav Matviienko
yesterday
I checked and its not. Thanks for the answer, that was the problem. The web api gave increased versioncode compared to real apk versioncode. Now everything is fine. Sorry everyone, that was a silly question with a terrible easy solution. :(
– Newbie1001
yesterday
3
3
are you really sure that the data on your web API equals the version name/version code of the latest app version?
– Vladyslav Matviienko
yesterday
are you really sure that the data on your web API equals the version name/version code of the latest app version?
– Vladyslav Matviienko
yesterday
I checked and its not. Thanks for the answer, that was the problem. The web api gave increased versioncode compared to real apk versioncode. Now everything is fine. Sorry everyone, that was a silly question with a terrible easy solution. :(
– Newbie1001
yesterday
I checked and its not. Thanks for the answer, that was the problem. The web api gave increased versioncode compared to real apk versioncode. Now everything is fine. Sorry everyone, that was a silly question with a terrible easy solution. :(
– Newbie1001
yesterday
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Well, there was nothing wrong with the code I posted. The problem was with the versioncode. Web Api gave back different versioncode, which did not match the apk's.
Thanks Vladyslav Matviienko for the suggestion.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Well, there was nothing wrong with the code I posted. The problem was with the versioncode. Web Api gave back different versioncode, which did not match the apk's.
Thanks Vladyslav Matviienko for the suggestion.
add a comment |
up vote
0
down vote
Well, there was nothing wrong with the code I posted. The problem was with the versioncode. Web Api gave back different versioncode, which did not match the apk's.
Thanks Vladyslav Matviienko for the suggestion.
add a comment |
up vote
0
down vote
up vote
0
down vote
Well, there was nothing wrong with the code I posted. The problem was with the versioncode. Web Api gave back different versioncode, which did not match the apk's.
Thanks Vladyslav Matviienko for the suggestion.
Well, there was nothing wrong with the code I posted. The problem was with the versioncode. Web Api gave back different versioncode, which did not match the apk's.
Thanks Vladyslav Matviienko for the suggestion.
answered yesterday
Newbie1001
227
227
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371446%2fapk-downloading-and-installing-successful-but-the-version-still-the-same-how-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
are you really sure that the data on your web API equals the version name/version code of the latest app version?
– Vladyslav Matviienko
yesterday
I checked and its not. Thanks for the answer, that was the problem. The web api gave increased versioncode compared to real apk versioncode. Now everything is fine. Sorry everyone, that was a silly question with a terrible easy solution. :(
– Newbie1001
yesterday