Changed download file path to internal storage

This commit is contained in:
dvdandroid 2016-08-25 17:39:09 +02:00
parent dabb222511
commit c86c2661af
2 changed files with 35 additions and 4 deletions

View File

@ -1,18 +1,22 @@
package com.topjohnwu.magisk;
import android.Manifest;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
@ -62,6 +66,9 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
@IdRes
private int mSelectedId = R.id.magisk;
private String mLastLink;
private boolean mLastIsApp;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -180,6 +187,17 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
new DownloadFile(this, mLastLink, mLastIsApp).execute();
} else {
Toast.makeText(this, R.string.permissionNotGranted, Toast.LENGTH_LONG).show();
}
}
private class CheckUpdates extends AsyncTask<Void, Void, String> {
private final Context context;
@ -271,7 +289,16 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
.setPositiveButton(R.string.update, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
new DownloadFile(context, link, app);
mLastLink = link;
mLastIsApp = app;
if (ActivityCompat.checkSelfPermission(WelcomeActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
&& Build.VERSION.SDK_INT >= 23) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
return;
}
new DownloadFile(context, link, app).execute();
}
})
.setNegativeButton(R.string.no_thanks, null)
@ -296,10 +323,14 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
this.link = link;
this.context = context;
File dir = new File(Environment.getExternalStorageDirectory() + "/Magisk");
if (!dir.exists()) dir.mkdir();
if (apk) {
downloadFile = new File(getFilesDir() + "/MagiskManager.apk");
downloadFile = new File(dir + "/MagiskManager.apk");
} else {
downloadFile = new File(getFilesDir() + "/Magisk.zip");
downloadFile = new File(dir + "/Magisk.zip");
}
Toast.makeText(context, downloadFile.getPath(), Toast.LENGTH_SHORT).show();

View File

@ -63,6 +63,6 @@
<string name="no_thanks">No, thanks</string>
<string name="never_show_again">Don\'t show again</string>
<string name="error_download_file">Error downloading file</string>
<string name="flash_recovery">File downloaded, you can flash it in recovery</string>
<string name="flash_recovery">File downloaded in Magisk directory, you can flash it in recovery</string>
</resources>