The problem is, after I download .apk-file from server using this method:
public void Update(String apkName) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
File file = new File("/sdcard/Download/"+ apkName + ".apk");
if (file.exists()) {
file.delete();
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS + "/", apkName + ".apk");
DownloadManager manager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
}
then I use BroadCastReciever to take install-action when the download-operation is complete as follows:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// some codes here...
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)){
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/Download/" + apkName + ".apk")),
"application/vnd.android.package-archive");
startActivity(i);
} else {
}
}
};
getActivity().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
download_apk(apkName);
return rootView;
}
Now problem is when the download-opration is complete DownloadManager try to install apk-file and I get this which is "Parse Error/There is a Problem parsing the package".
after I click OK, true Install-page shows up (which is triggered by broadcastReciever).
I run this proccess in Activity and it was perfectly fine. As you see above this time it is in Fragment! is this could be the reason??
How can I stop DownloadManager from running apk Automatically? can anybody help me out?