I am developing an application for android which on downloading the upgrade prompts the user to install. But it shows "Parser error: There was a problem while parsing the package."after downloading the file successfully.
Following is my code to download the upgrade through download manager:-
public void startDownload(String url)
{
filename = url.substring(url.lastIndexOf("/") + 1, url.length());
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
Log.i("Downloaded filename", filename); request.setDestinationInExternalPublicDir(Environment.getExternalStorageState(), "Upgrade Download/"+ filename);
Log.i("Download Path", Environment.getExternalStorageState() + "/Upgrade Download/" + filename);
request.allowScanningByMediaScanner();
request.setMimeType("application/vnd.android.package-archive"); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
// Start download
DownloadManager dm = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
dm.enqueue(request);
IntentFilter intentFilter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
activity.registerReceiver(onComplete, intentFilter);
}
And in the BroadcastReceiver it shows the popup to install the application.
BroadcastReceiver:-
BroadcastReceiver onComplete = new BroadcastReceiver()
{
public void onReceive(Context ctxt, Intent intent)
{
File file = new File(Environment.getExternalStorageState() + "/Upgrade Download", filename);
Log.i("open filename",""+ file.getPath());
Log.i("intent",""+ intent);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctxt.startActivity(i);
}
};
Please provide me solution to above issue.Thank You.