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

Unhandled Exception: PlatformException(PermissionHandler.PermissionManager, Unable to detect current Android Activity., null) #334

Closed
yinzelin627 opened this issue Jun 22, 2020 · 14 comments
Labels
platform: android Issue is related to the Android platform. status: closed (missing info) Indicates the issue was automatically closed due to a lack of information. status: triage Indicates that this issue needs to be analyzed and decorated with the appropriate labels

Comments

@yinzelin627
Copy link

E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(PermissionHandler.PermissionManager, Unable to detect current Android Activity., null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)

#2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#3 MethodChannelPermissionHandler.requestPermissions (package:permission_handler_platform_interface/src/method_channel/method_channel_permission_handler.dart:66:30)
#4 PermissionListActions.request (package:permission_handler/permission_handler.dart:105:16)
#5 PermissionUtil.deal (package:fluttermodule/common/utils/permission_util.dart:13:23)
#6 _DemoImagePictureState.loadAssets (package:fluttermodule/page/demo_image_picture.dart:67:43)
#7 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:779:19)
#8 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:862:36)
#9 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#10 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11)
#11 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282:5)
#12 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:217:7)
#13 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:475:9)
#14 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
#15 PointerRouter._dispatchEventToRoutes. (package:flutter/src/gestures/pointer_router.dart:122:9)
#16 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
#17 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18)
#18 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7)
#19 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
#20 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
#21 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
#22 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
#23 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
#24 _rootRunUnary (dart:async/zone.dart:1196:13)
#25 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#26 _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
#27 _invoke1 (dart:ui/hooks.dart:275:10)
#28 _dispatchPointerDataPacket (dart:ui/hooks.dart:184:5)

@ghost
Copy link

ghost commented Dec 17, 2020

PermissionHandler.PermissionManager, Unable to detect current Android Activity., null)

@ghost
Copy link

ghost commented Dec 17, 2020

if (await permission.isGranted) {
// Either the permission was already granted before or the user just granted it.
return true;
}

@Sempakonka
Copy link

Sempakonka commented Jan 7, 2021

Hi @CentForever
Can you provide some more information? e.g. the version you are using and the output of the flutter doctor -v command. I can't seem to reproduce your issue.
Also, could this be related, or even a duplicate of #269?

@Sempakonka Sempakonka added platform: android Issue is related to the Android platform. status: needs more info We need more information before we can continue work on this issue. status: triage Indicates that this issue needs to be analyzed and decorated with the appropriate labels labels Jan 7, 2021
@rezazrna
Copy link

any update?, i had the same issue

@no-response
Copy link

no-response bot commented Mar 22, 2021

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@no-response no-response bot closed this as completed Mar 22, 2021
@nmfisher
Copy link

nmfisher commented Mar 22, 2021

Can we reopen this? Same issue when running Permission.microphone.request() from a non-UI isolate (on plugin version 6.1.1).

D/permissions_handler(14367): Unable to detect current Activity.
I/flutter (14367): PlatformException(PermissionHandler.PermissionManager, Unable to detect current Android Activity., null, null)

C:\Users\Nick\Documents\Projects\flutter_isolate>flutter doctor -v
[√] Flutter (Channel master, 2.1.0-13.0.pre.194, on Microsoft Windows [Version 10.0.18363.1440], locale en-AU)
• Flutter version 2.1.0-13.0.pre.194 at C:\flutter
• Framework revision e58ee0fbc7 (12 hours ago), 2021-03-22 13:06:06 +0800
• Engine revision e6db3a275e
• Dart version 2.13.0 (build 2.13.0-149.0.dev)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at C:\Users\Nick\AppData\Local\Android\sdk
• Platform android-30, build-tools 29.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 3.6)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] VS Code (version 1.54.3)
• VS Code at C:\Users\Nick\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.20.0

[√] Connected device (3 available)
• SM J260FU (mobile) • aca90691 • android-arm • Android 8.1.0 (API 27)
• Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.90
• Edge (web) • edge • web-javascript • Microsoft Edge 89.0.774.57

• No issues found!

@felipecpassos
Copy link

I have the same problem as @nmfisher
Please help.

@nmfisher
Copy link

nmfisher commented Apr 8, 2021

Just spent a few hours digging through the plugin to see how this can be fixed.

Background - I want to request microphone permissions from some code that's running in a secondary FlutterEngine that is created in a background isolate. On Android, this FlutterEngine is created without an associated Activity, which is causing the error message "Unable to detect current Android Activity".

As far as I can see, Android has no way of requesting permissions without an Activity.

As a workaround, you need to launch a temporary/invisible Activity that handles the permission request, then kills itself when done.

I've created a proof-of-concept here but this definitely isn't production-ready (for example, concurrent/asynchronous requests (without await) on the Dart side won't complete properly.

The reason I'm not going to finish it off is because it's trivial enough for me to just request permissions in the foreground. I figured I'd push to GitHub in case anyone wants to take it further.

@FadiChaalab
Copy link

I also need to check permission in background. How did you get the workaround and please provide a link for that or just example of code here.

@kcibdev
Copy link

kcibdev commented Jan 20, 2022

Is there any update on this?

@emreedgu
Copy link

low level coded beauty ?

@Rumike7
Copy link

Rumike7 commented Mar 15, 2023

So we can't ask permission from background with this package?

@xbug42
Copy link

xbug42 commented Apr 27, 2023

The 'active' issue is here : #269

@mvanbeusekom mvanbeusekom added status: closed (missing info) Indicates the issue was automatically closed due to a lack of information. and removed status: needs more info We need more information before we can continue work on this issue. labels Jul 17, 2023
@AwaisQazii
Copy link

same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: android Issue is related to the Android platform. status: closed (missing info) Indicates the issue was automatically closed due to a lack of information. status: triage Indicates that this issue needs to be analyzed and decorated with the appropriate labels
Projects
None yet
Development

No branches or pull requests