Skip to content

Commit

Permalink
Merge pull request #28 from natsuk4ze/refactor
Browse files Browse the repository at this point in the history
Fix Returning false when permission granted by default
  • Loading branch information
natsuk4ze authored Jul 6, 2023
2 parents 8b1104c + 8c92568 commit 71b7595
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.6.2

* FIX: Returning false when permission granted by default when calling `hasAccess()`,`requestAccess()` in Android.
* UPDATE: Include maxSdkVersion as a key to write in AndroidManifest. *It is not necessary, but it is recommended.

## 1.6.1

* UPDATE: We have made a stronger typing. `Gal`,`GalException`,`MethodChannelGal` has `@immutable` now.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Add the following key to your _Info.plist_ file, located in
Add the following key to your _AndroidManifest_ file, located in
`<project root>/android/app/src/main/AndroidManifest.xml`:

* `<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />` - you can copy from [AndroidManifest.xml in example](https://github.com/natsuk4ze/gal/blob/main/example/android/app/src/main/AndroidManifest.xml).
* `<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29" />` - you can copy from [AndroidManifest.xml in example](https://github.com/natsuk4ze/gal/blob/main/example/android/app/src/main/AndroidManifest.xml).

## ✅Usage

Expand Down
11 changes: 7 additions & 4 deletions android/src/main/java/studio/midoridesign/gal/GalPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class GalPlugin
private static final Uri IMAGE_URI = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
private static final Uri VIDEO_URI = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
private static final int PERMISSION_REQUEST_CODE = 1317298; // Anything unique in the app.
private static final boolean hasAccessByDefault = Build.VERSION.SDK_INT < Build.VERSION_CODES.M
|| Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;

private MethodChannel channel;
private FlutterPluginBinding pluginBinding;
Expand Down Expand Up @@ -88,10 +90,14 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
break;
}
case "hasAccess": {
result.success(hasAccess());
result.success(hasAccessByDefault ? true : hasAccess());
break;
}
case "requestAccess": {
if (hasAccessByDefault) {
result.success(true);
return;
}
requestAccess().thenAccept(result::success);
break;
}
Expand Down Expand Up @@ -143,9 +149,6 @@ private void open() {
// When API >=29,<23 always true.
private boolean hasAccess() {
Context context = pluginBinding.getApplicationContext();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
return true;
}
int hasAccess = ContextCompat.checkSelfPermission(context, PERMISSION);
return hasAccess == PackageManager.PERMISSION_GRANTED;
}
Expand Down
3 changes: 2 additions & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
<uses-permission android:name="android.permission.INTERNET"/>

<!-- Gal: If supports API <29 add this key :Gal-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29" />
<!-- Gal: If supports API <29 add this key :Gal-->

</manifest>
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.6.1"
version: "1.6.2"
http_parser:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: gal
description: Gal is a Flutter plugin for handle native gallary apps. Easily open or save media files to native gallery apps.
version: 1.6.1
version: 1.6.2
homepage: https://pub.dev/packages/gal
repository: https://github.com/natsuk4ze/gal

Expand Down

0 comments on commit 71b7595

Please sign in to comment.