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

[Bug]: Calling the permission crashes the app when showing the permission request dialog. Only present in android. No issue in IOS devices. #1623

Open
3 of 8 tasks
brishav opened this issue Jan 7, 2025 · 3 comments
Assignees

Comments

@brishav
Copy link

brishav commented Jan 7, 2025

Please check the following before submitting a new issue.

Please select affected platform(s)

  • Android
  • iOS
  • Linux
  • macOS
  • Web
  • Windows

Steps to reproduce

Deny permission to make the app ask for the permission.

Expected results

Needed to deny or accept the permission.

Actual results

java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=109, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=2; index=-1
E/AndroidRuntime( 9691): at android.app.ActivityThread.deliverResults(ActivityThread.java:4845)
E/AndroidRuntime( 9691): at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
E/AndroidRuntime( 9691): at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
E/AndroidRuntime( 9691): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime( 9691): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime( 9691): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
E/AndroidRuntime( 9691): at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime( 9691): at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime( 9691): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime( 9691): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 9691): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime( 9691): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/AndroidRuntime( 9691): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=2; index=-1
E/AndroidRuntime( 9691): at com.odehbros.flutter_file_downloader.permissions.PermissionHandler.onRequestPermissionsResult(PermissionHandler.java:87)
E/AndroidRuntime( 9691): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onRequestPermissionsResult(FlutterEngineConnectionRegistry.java:746)
E/AndroidRuntime( 9691): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onRequestPermissionsResult(FlutterEngineConnectionRegistry.java:405)
E/AndroidRuntime( 9691): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onRequestPermissionsResult(FlutterActivityAndFragmentDelegate.java:912)
E/AndroidRuntime( 9691): at io.flutter.embedding.android.FlutterActivity.onRequestPermissionsResult(FlutterActivity.java:967)
E/AndroidRuntime( 9691): at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:8264)
E/AndroidRuntime( 9691): at android.app.Activity.dispatchActivityResult(Activity.java:8114)
E/AndroidRuntime( 9691): at android.app.ActivityThread.deliverResults(ActivityThread.java:4838)
E/AndroidRuntime( 9691): ... 11 more

Code sample

Code sample
[Paste your code here]

Screenshots or video

Future determinePosition() async {
try {
bool serviceEnabled;
LocationPermission permission;

  // Test if location services are enabled.
  serviceEnabled = await Geolocator.isLocationServiceEnabled();
  if (!serviceEnabled) {
    // Location services are not enabled don't continue
    // accessing the position and request users of the
    // App to enable the location services.
    return Future.error(
        'Please enable your location, it seems to be turned off.');
  }

  permission = await Geolocator.checkPermission();
  if (permission == LocationPermission.denied) {
    permission = await Geolocator.requestPermission();
    if (permission == LocationPermission.denied) {
      // Permissions are denied, next time you could try
      // requesting permissions again (this is also where
      // Android's shouldShowRequestPermissionRationale
      // returned true. According to Android guidelines
      // your App should show an explanatory UI now.
      return Future.error('Location permissions are denied');
    }
  }

  if (permission == LocationPermission.deniedForever) {
    // Permissions are denied forever, handle appropriately.
    return Future.error(
        'Location permissions are permanently denied, we cannot request permissions. Please give permission and try again.');
  }

  final LocationSettings locationSettings = LocationSettings(
    accuracy: LocationAccuracy.high,
    timeLimit: Duration(seconds: 3),
    distanceFilter: 100,
  );
  return await Geolocator.getCurrentPosition(
      locationSettings: locationSettings);
} catch (e) {
  return Future.error('Location can not be found');
}

}

Version

geolocator: ^13.0.2

Flutter Doctor output

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on macOS 15.2 24C101 darwin-arm64, locale en-NP)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.87.2)
[✓] Connected device (5 available)
[✓] Network resources

• No issues found!

@TimHoogstrate TimHoogstrate self-assigned this Jan 7, 2025
@TimHoogstrate
Copy link
Contributor

Dear @brishav,

On what Android OS version and device are you testing this?

Kind regards,

@TimHoogstrate TimHoogstrate added the status: needs more info We need more information before we can continue work on this issue. label Jan 7, 2025
@brishav
Copy link
Author

brishav commented Jan 13, 2025

im recently testing on emulator version 29. but the prob occured in version 33 34 as well

@github-actions github-actions bot removed the status: needs more info We need more information before we can continue work on this issue. label Jan 13, 2025
@sjmamani
Copy link

I got the same problem. In my case, a few days ago upgrade a package to a new version and it seems this cause to crash when request the permission. I don't know the exact reason but it has to be some conflicts between packages. The packages is flutter_file_downloader (the solution was to revert the upgrade commit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants