use external files dir for temporary update apk download
This commit is contained in:
parent
b237b1a49f
commit
57ee1ec1ca
@ -590,10 +590,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
break;
|
break;
|
||||||
case REQUEST_UPDATE_FINISHED:
|
case REQUEST_UPDATE_FINISHED:
|
||||||
// clean up update apk
|
// clean up update apk
|
||||||
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + '/' +
|
deleteUpdateFile();
|
||||||
Environment.DIRECTORY_DOWNLOADS + "/iitcUpdate.apk");
|
|
||||||
if (file != null) file.delete();
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
@ -649,20 +646,27 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteUpdateFile() {
|
||||||
|
File file = new File(getExternalFilesDir(null).toString() + "/iitcUpdate.apk");
|
||||||
|
if (file != null) file.delete();
|
||||||
|
}
|
||||||
|
|
||||||
public void updateIitc(String url) {
|
public void updateIitc(String url) {
|
||||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
||||||
request.setDescription("downloading IITCm update apk...");
|
request.setDescription("downloading IITCm update apk...");
|
||||||
request.setTitle("IITCm Update");
|
request.setTitle("IITCm Update");
|
||||||
request.allowScanningByMediaScanner();
|
request.allowScanningByMediaScanner();
|
||||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "iitcUpdate.apk");
|
Uri fileUri = Uri.parse("file://" + getExternalFilesDir(null).toString() + "/iitcUpdate.apk");
|
||||||
|
request.setDestinationUri(fileUri);
|
||||||
|
// remove old files (iitcm cleans up after installation, but you never know...)
|
||||||
|
deleteUpdateFile();
|
||||||
// get download service and enqueue file
|
// get download service and enqueue file
|
||||||
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
|
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
|
||||||
manager.enqueue(request);
|
manager.enqueue(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void installIitcUpdate() {
|
private void installIitcUpdate() {
|
||||||
String iitcUpdatePath = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' +
|
String iitcUpdatePath = getExternalFilesDir(null).toString() + "/iitcUpdate.apk";
|
||||||
Environment.DIRECTORY_DOWNLOADS + "/iitcUpdate.apk";
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.setDataAndType(Uri.fromFile(new File(iitcUpdatePath)), "application/vnd.android.package-archive");
|
intent.setDataAndType(Uri.fromFile(new File(iitcUpdatePath)), "application/vnd.android.package-archive");
|
||||||
startActivityForResult(intent, REQUEST_UPDATE_FINISHED);
|
startActivityForResult(intent, REQUEST_UPDATE_FINISHED);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user