googlesamples / easypermissions

Simplify Android M system permissions
https://firebaseopensource.com/projects/googlesamples/easypermissions/
Apache License 2.0
9.87k stars 1.45k forks source link

Can we use this lib on a method that has param? #169

Closed leohan1992 closed 7 years ago

leohan1992 commented 7 years ago

I've tried this

@AfterPermissionGranted(1001)
    private void download(String url) {
        String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
        if (EasyPermissions.hasPermissions((Context) mView, perms)) {
            ProgressDialog progressDialog = new ProgressDialog((Context) mView);
            progressDialog.setMax(100);
            progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDialog.setCancelable(false);
            String apkPath = AppConstants.FILE_DOWNLOAD_PATH + "/" + System.currentTimeMillis() + ".apk";
            DownloadUtil downloadUtil = new DownloadUtil(url, apkPath, new ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    if (done) {
                        if (progressDialog.isShowing()) {
                            progressDialog.dismiss();
                        }
                        ApkUtil.installApk((Context) mView, apkPath);
                    }
                    progressDialog.setProgress((int) ((bytesRead * 100) / contentLength));
                }

                @Override
                public void onFailed() {
                    if (progressDialog.isShowing()) {
                        progressDialog.dismiss();
                    }
                    ToastUtil.makeShort((Context) mView, ((Context) mView).getString(R.string.network_error_tips));
                }

                @Override
                public void onStart() {
                    if (!progressDialog.isShowing()) {
                        progressDialog.show();
                    }
                }
            });
            downloadUtil.start();
        } else {
            EasyPermissions.requestPermissions((MainActivity) mView, "我们需要外部存储用于下载更新", 1001, perms);
        }

it will request permission,but didn't excute this method again when permission granted.Can I use @AfterPermissionGranter on a method that with param?

SUPERCILEX commented 7 years ago

@leohan1992 Nope, unfortunately not. We would have no idea what value to pass in for that parameter. You can work around this be keeping an instance of the url in your Activity/Fragment and then saving it in onSaveInstanceState.

leohan1992 commented 7 years ago

thanks,and will be support in future?

SUPERCILEX commented 7 years ago

Nope, it's impossible for us to know what value to pass in.