Fix some external storage permission issues

This commit is contained in:
topjohnwu 2017-10-14 00:36:10 +08:00
parent e140481f14
commit b2bb0d4f72
2 changed files with 8 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package com.topjohnwu.magisk;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
@ -17,6 +18,7 @@ import com.topjohnwu.magisk.components.Fragment;
import com.topjohnwu.magisk.container.Module;
import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils;
import java.util.ArrayList;
import java.util.List;
@ -36,9 +38,11 @@ public class ModulesFragment extends Fragment implements Topic.Subscriber {
@BindView(R.id.empty_rv) TextView emptyRv;
@OnClick(R.id.fab)
public void selectFile() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/zip");
startActivityForResult(intent, FETCH_ZIP_CODE);
Utils.runWithPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/zip");
startActivityForResult(intent, FETCH_ZIP_CODE);
});
}
private List<Module> listModules = new ArrayList<>();

View File

@ -45,7 +45,6 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
super(context);
mLink = link;
mFile = new File(Environment.getExternalStorageDirectory() + "/MagiskManager", filename);
mFile.getParentFile().mkdirs();
mInstall = install;
}
@ -80,6 +79,7 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
@Override
protected void onPreExecute() {
Activity activity = getActivity();
mFile.getParentFile().mkdirs();
progressDialog = ProgressDialog.show(activity, activity.getString(R.string.zip_download_title), activity.getString(R.string.zip_download_msg, 0));
}