Skip to content

Commit

Permalink
Changed download folder and fixed issue with installer not launching
Browse files Browse the repository at this point in the history
  • Loading branch information
7LPdWcaW authored and 7LPdWcaW committed Feb 25, 2017
1 parent ef7a501 commit 9da2b1e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions app/src/main/java/me/anon/grow/updater/DownloadActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.FileProvider;
Expand All @@ -23,6 +27,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import cz.msebera.android.httpclient.Header;
import me.anon.grow.helper.PermissionHelper;
Expand Down Expand Up @@ -92,10 +97,12 @@ private void downloadAndInstall()
return;
}

File folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

final ProgressBar progress = (ProgressBar)findViewById(R.id.progress);
AsyncHttpClient client = new AsyncHttpClient();
client.setUserAgent("Android/7LPdWcaW:GrowUpdater");
client.get(version.downloadUrl, new FileAsyncHttpResponseHandler(new File(getExternalCacheDir(), version.toString() + ".apk"))
client.get(version.downloadUrl, new FileAsyncHttpResponseHandler(new File(folder, version.toString() + ".apk"))
{
@Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, File file)
{
Expand All @@ -121,9 +128,19 @@ public void onReceive(Context ctxt, Intent intent)

registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

Uri uri = FileProvider.getUriForFile(DownloadActivity.this, getApplicationContext().getPackageName() + ".provider", getTargetFile());

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(FileProvider.getUriForFile(DownloadActivity.this, getApplicationContext().getPackageName() + ".provider", getTargetFile()), "application/vnd.android.package-archive");
intent.setDataAndType(uri, "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList)
{
String packageName = resolveInfo.activityInfo.packageName;
grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}

startActivity(intent);
}

Expand Down

0 comments on commit 9da2b1e

Please sign in to comment.