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

Unable to detect current Android Activity., null, null #552

Closed
Ronadlo7 opened this issue May 12, 2021 · 22 comments
Closed

Unable to detect current Android Activity., null, null #552

Ronadlo7 opened this issue May 12, 2021 · 22 comments
Labels
platform: android Issue is related to the Android platform.

Comments

@Ronadlo7
Copy link

[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(PermissionHandler.PermissionManager, Unable to detect current Android Activity., null, null)

@mvanbeusekom
Copy link
Member

@Ronadlo7 could you please provide more details?

  1. Which version of the plugin are you using?
  2. Output of the flutter doctor -v command?
  3. Which method are you calling when you receive this error?

Most likely you are calling the request method which needs an activity to be able to show the permission dialog while your app is in the background. This is not allowed and the plugin will return the above exception.

@mvanbeusekom mvanbeusekom 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. labels May 12, 2021
@Ronadlo7
Copy link
Author

Android depand on Flutter module ,flutter module depand on permission_handler: ^7.1.0,
run Android App, then call method of Permission.camera.request(), will appear ,
but run flutter module ,request this method is ok

@no-response no-response bot removed the status: needs more info We need more information before we can continue work on this issue. label May 12, 2021
@mvanbeusekom
Copy link
Member

Can you provide a reproduction example?

@mvanbeusekom mvanbeusekom added the status: needs more info We need more information before we can continue work on this issue. label May 12, 2021
@Ronadlo7
Copy link
Author

Can you provide contact information? provide example project?

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

#2 MethodChannelPermissionHandler.requestPermissions (package:permission_handler_platform_interface/src/method_channel/method_channel_permission_handler.dart:67:9)

#3 PermissionActions.request (package:permission_handler/permission_handler.dart:48:31)

@no-response no-response bot removed the status: needs more info We need more information before we can continue work on this issue. label May 12, 2021
@mvanbeusekom
Copy link
Member

mvanbeusekom commented May 12, 2021

@Ronadlo7 the easiest would be to create a GitHub gist. But if this is difficult you can drop an email to dev(at)baseflow.com

@Ronadlo7
Copy link
Author

ok,Sending a example project to your email of Sending to your mailbox

@Ronadlo7
Copy link
Author

It has been sent successfully, have you received it?

@mvanbeusekom
Copy link
Member

mvanbeusekom commented May 12, 2021

I received the file, downloading it and will have a look when I get some time. Maybe for future reference, run a flutter clean before you archive the project. This would have probably safe around 500 MB in file size.

@Ronadlo7
Copy link
Author

How is it, has it reproduced?

@JDDV
Copy link
Contributor

JDDV commented May 17, 2021

Hi @Ronadlo7, I've received the flutter project you're working on to help you with this issue.
As soon as I run your project I get directed to 'secondPage.dart', where there are 2 buttons.
The last button will call the checkCameraPermission method, but for me it didn't do anything.
I don't get the error you received, which was:

[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(PermissionHandler.PermissionManager, Unable to detect current Android Activity., null, null)

But I did notice that the permission was not added in the AndroidManifest.xml, which is mandatory if you want to ask permission to the user.

In your project folder structure go to Android > app > src > main > AndroidManifest.xml

If you open the AndroidManifest you should add the following line: <uses-permission android:name="android.permission.CAMERA"/>.

Clear instruction on how to set the permission handler up can be found here.

A full list of all the permission that are available can be found here. This is the AndroidManifest.xml from the example app which is included in the permission_handler plugin, you can always check the example app to see how it works!

I hope this will help you, please let us know if the issue is solved or not.

@Ronadlo7
Copy link
Author

I have add the permission in AndroidManifest.xml .
but still have this error

@Ronadlo7
Copy link
Author

you run Android project ,not flutter module ,because if you run flutter module is ok, this error is run Android project

@JDDV
Copy link
Contributor

JDDV commented May 17, 2021

I'm not entirely sure what you mean, but I've opened the project using the flutter_module_support folder, and I've opened the project using the Android folder. Both will run perfectly after adding the permission.

you run Android project ,not flutter module ,because if you run flutter module is ok, this error is run Android project

Just to be sure it's not a weird flutter/package issue, have you ran flutter clean followed by the command flutter pub get and tried it again?

If it did not help, can you explain the steps you take from the beginning (opening the project, and how you run the project and test the project and so on)? Because I can't seem to reproduce the issue

@Ronadlo7
Copy link
Author

you should be run AndroidToFlutter project ,not flutter_module_support folder ,

@Ronadlo7
Copy link
Author

AndroidToFlutter is Android Project ,it depend on flutter_module_support, so you should be run AndroidToFlutter Project ,then it have the problem

@JDDV
Copy link
Contributor

JDDV commented May 17, 2021

I can't open and run the NativeToFlutter app, it gives me an error saying 'File was loaded in the wrong encoding: 'UTF-8''. Reload in another encoding doesn't work either. In what language did you write the program, or what encoding did you use?

Here's what I get:

example

@Ronadlo7
Copy link
Author

there are three java file ,you shoule be replece:
1.MainActivity.java
MainActivity.java

2.NativeActivity.java
NativeActivity.java

3.TransitionActivity.java
TransitionActivity.java

@JDDV
Copy link
Contributor

JDDV commented May 18, 2021

I can't open the links you send me, I get an 404 error saying the page does not exist.
Maybe your repo is private or something?

here's what I see when I click on those links:

image

@Ronadlo7
Copy link
Author

now ,you can try again,

@JDDV
Copy link
Contributor

JDDV commented May 18, 2021

I did manage to get the app running now, but I still don't get the same error down here you get when I click on one of those 2 buttons.
Are you sure you're starting the intent at the right way?

[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(PermissionHandler.PermissionManager, Unable to detect current Android Activity., null, null)

This error shows that there is no Activity, so I think something goes wrong starting the intent where you ask for the permission.
I did see that you integrated the flutter module into your Android Project (I also used method A to check if that would have solved the issue somehow. But I saw you used method B which also worked the same way for me).
But have you also tried the next step, which is Adding a Flutter screen to an Android app?

I saw you took step one, but I did not see calling the intents as mentioned in step 2. I think if you succesfully call an intent the way the tutorial shows that the permission_handler will have an activity and the permission request will work.
Let me know if it worked!

@Ronadlo7
Copy link
Author

you also get this error? add FlutterView by TransitionActivity you can new Android Project by yourself ,then depend on flutter module, See if there is such an error

@JDDV
Copy link
Contributor

JDDV commented May 19, 2021

Hi @Ronadlo7, It took me a while because I had some troubles with my pc, but I figured out what the problem is.

In your method you do the following to start an intent:

    public void enterFlutter2(View view) {
        Intent intent = new Intent(this, TransitionActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("routeName", "/second");
        bundle.putString("arguments", "?{\"name\":\"" + "?????22" + "\"}");
        intent.putExtras(bundle);
        startActivityForResult(intent,100);
}

This way you do start an Intent, opening one of the screens you have made in Flutter, but the Activity will be null.

The way how you should start the activity is like this:

public void enterFlutter2(View view) {
        startActivity(
                FlutterActivity
                    .withNewEngine()
                    .initialRoute("/second")
                    .build(this));
    }

This is how you start a FlutterActivity, this way asking for the permission will work if you have added it to the AndroidManifest because the activity won't be null this way. The issue is closed, but if it still doesn't work let me know!

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.
Projects
None yet
Development

No branches or pull requests

3 participants