1313import android .view .View ;
1414import android .widget .ProgressBar ;
1515
16+ import androidx .annotation .NonNull ;
1617import androidx .core .content .ContextCompat ;
1718import androidx .core .content .FileProvider ;
1819
3940import java .io .File ;
4041import java .io .IOException ;
4142import java .io .OutputStream ;
43+ import java .util .ArrayList ;
4244import java .util .List ;
4345
4446import okhttp3 .Call ;
@@ -90,13 +92,11 @@ private void requestPermission() {
9092 */
9193
9294 @ Override
93- public void onGranted (List <String > permissions , boolean all ) {
94-
95- }
95+ public void onGranted (@ NonNull List <String > permissions , boolean allGranted ) {}
9696
9797 @ Override
98- public void onDenied (List <String > permissions , boolean never ) {
99- if (never ) {
98+ public void onDenied (@ NonNull List <String > permissions , boolean doNotAskAgain ) {
99+ if (doNotAskAgain ) {
100100 ToastUtils .show ("授权失败,请手动授予存储权限" );
101101 XXPermissions .startPermissionActivity (this , permissions );
102102 } else {
@@ -109,7 +109,7 @@ public void onDenied(List<String> permissions, boolean never) {
109109 protected void onRestart () {
110110 super .onRestart ();
111111 if (XXPermissions .isGranted (this , Permission .Group .STORAGE )) {
112- onGranted (null , true );
112+ onGranted (new ArrayList <>() , true );
113113 } else {
114114 requestPermission ();
115115 }
@@ -133,10 +133,10 @@ public void onSucceed(HttpData<List<SearchAuthorApi.Bean>> result) {
133133
134134 } else if (viewId == R .id .btn_main_post ) {
135135
136- EasyHttp .post (this )
136+ EasyHttp .post (MainActivity . this )
137137 .api (new SearchBlogsApi ()
138138 .setKeyword ("搬砖不再有" ))
139- .request (new HttpCallback <HttpData <SearchBlogsApi .Bean >>(this ) {
139+ .request (new HttpCallback <HttpData <SearchBlogsApi .Bean >>(MainActivity . this ) {
140140
141141 @ Override
142142 public void onSucceed (HttpData <SearchBlogsApi .Bean > result ) {
@@ -311,31 +311,31 @@ private void installApk(final Context context, final File file) {
311311 .permission (Permission .REQUEST_INSTALL_PACKAGES )
312312 .request (new OnPermissionCallback () {
313313 @ Override
314- public void onGranted (List <String > permissions , boolean all ) {
315- if (!all ) {
314+ public void onGranted (@ NonNull List <String > permissions , boolean allGranted ) {
315+ if (!allGranted ) {
316316 return ;
317317 }
318- Intent intent = new Intent ();
319- intent .setAction (Intent .ACTION_VIEW );
318+ Intent intent = new Intent (Intent .ACTION_VIEW );
320319 Uri uri ;
321320 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
322321 if (file instanceof FileContentResolver ) {
323322 uri = ((FileContentResolver ) file ).getContentUri ();
324323 } else {
325324 uri = FileProvider .getUriForFile (context , context .getPackageName () + ".provider" , file );
326325 }
327- intent .addFlags (Intent .FLAG_GRANT_READ_URI_PERMISSION | Intent .FLAG_GRANT_WRITE_URI_PERMISSION );
328326 } else {
329327 uri = Uri .fromFile (file );
330328 }
331329
332330 intent .setDataAndType (uri , "application/vnd.android.package-archive" );
333331 intent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
332+ // 对目标应用临时授权该 Uri 读写权限
333+ intent .addFlags (Intent .FLAG_GRANT_READ_URI_PERMISSION | Intent .FLAG_GRANT_WRITE_URI_PERMISSION );
334334 context .startActivity (intent );
335335 }
336336
337337 @ Override
338- public void onDenied (List <String > permissions , boolean never ) {}
338+ public void onDenied (@ NonNull List <String > permissions , boolean doNotAskAgain ) {}
339339 });
340340 }
341341}
0 commit comments