java - Trying to update my apk programmatically results in parse error -


i need update application without google play. uploaded apk server downloaded when needed.

it's downloaded fine following code, when installation intent started it's throwing: "parse error: there problem parsing package"

if try run downloaded apk manually, still gives same error.

but, if transfer apk usb , run it, installs smoothly. problem not apk itself.

here task class:

class update implements runnable {     @override     public void run() {         ftpclient ftpclient = new ftpclient();         try {             ftpclient.connect(inetaddress.getbyname("mysite.com"));             ftpclient.login("mysite.com", "123456"));             ftpclient.enterlocalpassivemode();             string remotefile1 = "/httpdocs/program/app-release.apk";             string downpath = getexternalstoragepublicdirectory(directory_downloads).getabsolutepath();             file myapk = new file(downpath + "/app-release.apk");             outputstream outputstream1 = new bufferedoutputstream(new fileoutputstream(myapk));             boolean success = ftpclient.retrievefile(remotefile1, outputstream1);             outputstream1.close();             myapk.setreadable(true, false);             if (!success) {                 ftpclient.logout();                 ftpclient.disconnect();                 return;             } else {                 intent promptinstall = new intent(intent.action_view)                         .setdataandtype(uri.fromfile(myapk), "application/vnd.android.package-archive")                         .addflags(intent.flag_activity_new_task);                 startactivity(promptinstall);             }         }         catch (exception ex) {             //catch exception         }     } } 

alright, own mistake. sorry scanned , frustrated fine working code.

the reason me, trying update app ran directly android studio on usb. despite it's been running on "release" mode, throws parse error on newly downloaded apk file (i'm still not sure why).

so, generated signed apk proper (lower) versioning; copy phone , install. then, app can download , run newer versioned apk file. updating expected.

let example case did same thing me. use generated apk when testing manual update function.

lastly, want share code. changed ftp direct download via httpurlconnection. both versions work fine (the code in question , this). feel free choose 1 suits job.

class update implements runnable {     @override     public void run() {         try {             url url = new url("mysite.com/app-release.apk");             httpurlconnection c = (httpurlconnection) url.openconnection();             c.setrequestmethod("get");             c.setdooutput(true);             c.connect();             string path = getexternalstoragepublicdirectory(directory_downloads).getabsolutepath();             file file = new file(path);             file outputfile = new file(file, "app-release.apk");             fileoutputstream fos = new fileoutputstream(outputfile);             inputstream = c.getinputstream();             byte[] buffer = new byte[1024];             int len1 = 0;             while ((len1 = is.read(buffer)) != -1) {                 fos.write(buffer, 0, len1);             }             fos.close();             is.close();             intent promptinstall = new intent(intent.action_view)                     .setdataandtype(uri.fromfile(outputfile), "application/vnd.android.package-archive")                     .addflags(intent.flag_activity_new_task);             startactivity(promptinstall);         } catch (exception ex) {             //catch exception         }     } } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -