Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

移除对 READ_EXTERNAL_STORAGE 和 WRITE_EXTERNAL_STORAGE 权限的请求( Android 10 和 Android 11,不再请求这些权限);Android 12 及以上版本,请求 POST_NOTIFICATIONS 权限; 支持“升级到gradle到8.7” #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.pub/

build/
.flutter-plugins-dependencies
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.3
* 移除对 READ_EXTERNAL_STORAGE 和 WRITE_EXTERNAL_STORAGE 权限的请求( Android 10 和 Android 11,不再请求这些权限)
* Android 12 及以上版本,请求 POST_NOTIFICATIONS 权限
* 支持“升级到gradle到8.7”
## 0.4.2
* fix issues(#76) support android 13.
## 0.4.1
Expand Down
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:8.5.2'
}
}

Expand All @@ -25,6 +25,7 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
namespace "com.example.r_upgrade"
compileSdkVersion 33

defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.pm.PackageManager;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.annotation.VisibleForTesting;
import androidx.core.app.ActivityCompat;
Expand Down Expand Up @@ -33,8 +34,9 @@ public void requestPermissions(
if (Build.VERSION.SDK_INT >= 33) {
if (ongoing) {
callback.onResult("downloadPermission", "Notification permission request ongoing");
return;
}
if (notificationVisibility != 2&&!hasNotificationPermission(activity)) {
if (notificationVisibility != 2 && !hasNotificationPermission(activity)) {
permissionsRegistry.addListener(
new StorageRequestPermissionsListener(new ResultCallback() {
@Override
Expand All @@ -52,9 +54,13 @@ public void onResult(String errorCode, String errorDescription) {
// Permissions already exist. Call the callback with success.
callback.onResult(null, null);
}
} else if (Build.VERSION.SDK_INT < 30 && (!hasReadStoragePermission(activity) || !hasWritePermission(activity))) {
} else if (Build.VERSION.SDK_INT >= 29 && Build.VERSION.SDK_INT < 33) {
// For Android 10 and Android 11, we don't request storage permissions
callback.onResult(null, null);
} else {
if (ongoing) {
callback.onResult("downloadPermission", "Read/Write External Storage permission request ongoing");
return;
}
permissionsRegistry.addListener(
new StorageRequestPermissionsListener(new ResultCallback() {
Expand All @@ -69,9 +75,6 @@ public void onResult(String errorCode, String errorDescription) {
activity,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
STORAGE_REQUEST_ID);
} else {
// Permissions already exist. Call the callback with success.
callback.onResult(null, null);
}
}

Expand All @@ -81,16 +84,6 @@ private boolean hasNotificationPermission(Activity activity) {
== PackageManager.PERMISSION_GRANTED;
}

private boolean hasReadStoragePermission(Activity activity) {
return ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED;
}

private boolean hasWritePermission(Activity activity) {
return ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED;
}

@VisibleForTesting
public static final class StorageRequestPermissionsListener
implements PluginRegistry.RequestPermissionsResultListener {
Expand All @@ -100,7 +93,6 @@ public static final class StorageRequestPermissionsListener
// we've responded before and bail out of handling the callback manually if this is a repeat
// call.
boolean alreadyCalled = false;

final ResultCallback callback;

@VisibleForTesting
Expand Down Expand Up @@ -136,4 +128,4 @@ public boolean onRequestPermissionsResult(int id, String[] permissions, int[] gr
}
}
}
}
}
25 changes: 12 additions & 13 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:r_upgrade/r_upgrade.dart';
Expand Down Expand Up @@ -128,7 +127,7 @@ class _MyAppState extends State<MyApp> {
title: Text('get version from app store(WeChat)'),
trailing: iosVersion != null
? Text(iosVersion!,
style: Theme.of(context).textTheme.subtitle2!.copyWith(
style: Theme.of(context).textTheme.titleSmall!.copyWith(
color: Colors.grey,
))
: null,
Expand All @@ -150,7 +149,7 @@ class _MyAppState extends State<MyApp> {
ListTile(
title: Text(
S.of(context).Notification_Related,
style: Theme.of(context).textTheme.headline6!.copyWith(
style: Theme.of(context).textTheme.titleLarge!.copyWith(
fontWeight: FontWeight.w600,
),
),
Expand Down Expand Up @@ -232,7 +231,7 @@ class _MyAppState extends State<MyApp> {
ListTile(
title: Text(
S.of(context).Install_Related,
style: Theme.of(context).textTheme.headline6!.copyWith(
style: Theme.of(context).textTheme.titleLarge!.copyWith(
fontWeight: FontWeight.w600,
),
),
Expand Down Expand Up @@ -269,15 +268,15 @@ class _MyAppState extends State<MyApp> {
ListTile(
title: Text(
S.of(context).Install_Type_Silent_Tip,
style: Theme.of(context).textTheme.subtitle2?.copyWith(
color: Theme.of(context).errorColor,
style: Theme.of(context).textTheme.titleSmall?.copyWith(
color: Theme.of(context).colorScheme.error,
),
),
),
ListTile(
title: Text(
S.of(context).Update_the_related,
style: Theme.of(context).textTheme.headline6!.copyWith(
style: Theme.of(context).textTheme.titleLarge!.copyWith(
fontWeight: FontWeight.w600,
),
),
Expand Down Expand Up @@ -323,7 +322,7 @@ class _MyAppState extends State<MyApp> {
},
trailing: androidVersion != null
? Text(androidVersion!,
style: Theme.of(context).textTheme.subtitle2!.copyWith(
style: Theme.of(context).textTheme.titleSmall!.copyWith(
color: Colors.grey,
))
: null,
Expand Down Expand Up @@ -440,7 +439,7 @@ class _MyAppState extends State<MyApp> {
ListTile(
title: Text(
S.of(context).Hot_update_related,
style: Theme.of(context).textTheme.headline6!.copyWith(
style: Theme.of(context).textTheme.titleLarge!.copyWith(
fontWeight: FontWeight.w600,
),
),
Expand Down Expand Up @@ -513,7 +512,7 @@ class _MyAppState extends State<MyApp> {
ListTile(
title: Text(
S.of(context).Incremental_updating,
style: Theme.of(context).textTheme.headline6!.copyWith(
style: Theme.of(context).textTheme.titleLarge!.copyWith(
fontWeight: FontWeight.w600,
),
),
Expand Down Expand Up @@ -579,7 +578,7 @@ class _MyAppState extends State<MyApp> {
ListTile(
title: Text(
S.of(context).History_related,
style: Theme.of(context).textTheme.headline6!.copyWith(
style: Theme.of(context).textTheme.titleLarge!.copyWith(
fontWeight: FontWeight.w600,
),
),
Expand All @@ -589,7 +588,7 @@ class _MyAppState extends State<MyApp> {
trailing: lastId != null
? Text(
lastId.toString(),
style: Theme.of(context).textTheme.subtitle2!.copyWith(
style: Theme.of(context).textTheme.titleSmall!.copyWith(
color: Colors.grey,
),
)
Expand Down Expand Up @@ -626,7 +625,7 @@ class _MyAppState extends State<MyApp> {
),
trailing: lastStatus != null
? Text(getStatus(lastStatus),
style: Theme.of(context).textTheme.subtitle2!.copyWith(
style: Theme.of(context).textTheme.titleSmall!.copyWith(
color: Colors.grey,
))
: null,
Expand Down
Loading