Download file already success but when install it has an error “application-not-installed”
I already use INSTALL_NON_MARKET_APPS permission
Install prompt already there but everytime I tried , it’s always “application-not-installed” error.
public void Update(String apkurl){
try {
URL url = new URL(apkurl);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
try{
c.connect();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),e.getMessage() , Toast.LENGTH_LONG).show();
}
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "prov1.apk");
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = 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();//till here, it works fine - .apk is download to my sdcard in download file
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "prov1.apk")), "application/vnd.android.package-archive");
startActivity(intent);
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "Update error!", Toast.LENGTH_LONG).show();
}
}
I already read another question about this topic but still stuck. I am really thank for your help.
One of the problems it could be that you already have some app with the same package name.
For example if you try to install com.something.prov1 the same package it might already exist. if that is the case than first uninstall the app