Caldarie / flutter_tflite_audio

Audio classification Tflite package for flutter (iOS & Android). Can support Google Teachable Machine models
MIT License
64 stars 26 forks source link

Permission request error #19

Closed andrejvujic closed 3 years ago

andrejvujic commented 3 years ago
D/Tflite_audio( 7874): Check for permissions
D/Tflite_audio( 7874): Permission requested.
E/EventChannel#startAudioRecognition( 7874): Failed to open event stream
E/EventChannel#startAudioRecognition( 7874): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.requestPermissions(java.lang.String[], int)' on a null object reference
E/EventChannel#startAudioRecognition( 7874):    at androidx.core.app.ActivityCompat.requestPermissions(ActivityCompat.java:502)
E/EventChannel#startAudioRecognition( 7874):    at flutter.tflite_audio.TfliteAudioPlugin.requestMicrophonePermission(TfliteAudioPlugin.java:310)
E/EventChannel#startAudioRecognition( 7874):    at flutter.tflite_audio.TfliteAudioPlugin.checkPermissions(TfliteAudioPlugin.java:303)
E/EventChannel#startAudioRecognition( 7874):    at flutter.tflite_audio.TfliteAudioPlugin.onListen(TfliteAudioPlugin.java:221)
E/EventChannel#startAudioRecognition( 7874):    at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler.onListen(EventChannel.java:188)
E/EventChannel#startAudioRecognition( 7874):    at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler.onMessage(EventChannel.java:167)
E/EventChannel#startAudioRecognition( 7874):    at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/EventChannel#startAudioRecognition( 7874):    at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
E/EventChannel#startAudioRecognition( 7874):    at android.os.MessageQueue.nativePollOnce(Native Method)
E/EventChannel#startAudioRecognition( 7874):    at android.os.MessageQueue.next(MessageQueue.java:335)
E/EventChannel#startAudioRecognition( 7874):    at android.os.Looper.loop(Looper.java:206)
E/EventChannel#startAudioRecognition( 7874):    at android.app.ActivityThread.main(ActivityThread.java:8512)
E/EventChannel#startAudioRecognition( 7874):    at java.lang.reflect.Method.invoke(Native Method)
E/EventChannel#startAudioRecognition( 7874):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
E/EventChannel#startAudioRecognition( 7874):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

════════ Exception caught by services library ══════════════════════════════════
The following PlatformException was thrown while activating platform stream on channel startAudioRecognition:
PlatformException(error, Attempt to invoke virtual method 'void android.app.Activity.requestPermissions(java.lang.String[], int)' on a null object reference, null, null)

When the exception was thrown, this was the stack
#0      StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:597
#1      MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:158
<asynchronous suspension>
#2      EventChannel.receiveBroadcastStream.<anonymous closure>
package:flutter/…/services/platform_channel.dart:545
<asynchronous suspension>
════════════════════════════════════════════════════════════════════════════════
Caldarie commented 3 years ago

Hi @andrejvujic

Thanks for bringing up the issue.

If i may ask, did you receive this error from the example? Or are you using your own code with the plugin?

andrejvujic commented 3 years ago

My own code, however I did everything like in the example.

On Fri, 22 Oct 2021 at 03:16 Michael Nguyen @.***> wrote:

Hi @andrejvujic https://github.com/andrejvujic

Thanks for bringing up the issue.

If i may ask, did you receive this error from the example? Or are you using your own code with the plugin?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Caldarie/flutter_tflite_audio/issues/19#issuecomment-949156890, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQKOTJQRQXKGJYS6EFM5D7DUIC3O5ANCNFSM5GO2CYAQ .

Caldarie commented 3 years ago

Hi @andrejvujic

I understand.

Considering that this is an unusual error, would it be possible for you to clone this project and run the example? I would like to know if you still receive the same error.

andrejvujic commented 3 years ago

I have already run the example. It works perfectly, I only had to set the ndkVersion to 16 in app/build.gradle because it wouldn’t compile. It’s a problem with my project. I don’t know what it is, I’ve done everything like shown on pub.dev.

On Fri, 22 Oct 2021 at 06:30 Michael Nguyen @.***> wrote:

Hi @andrejvujic https://github.com/andrejvujic

I understand.

Considering that this is an unusual error, would it be possible for you to clone this project and run the example? I would like to know if you still receive the same error.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Caldarie/flutter_tflite_audio/issues/19#issuecomment-949278271, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQKOTJW4FDEGIVLAC2XA32DUIDSETANCNFSM5GO2CYAQ .

Caldarie commented 3 years ago

Hmm, if it's not too much to ask, would it be possible to share your project or a part of your code? Perhaps i can investigate the issue for you.

andrejvujic commented 3 years ago

The project is large, it has about 16000 lines of code, so I couldn’t send you the code. However I have a private GitHub repo I could give you access to.

On Fri, 22 Oct 2021 at 06:39 Michael Nguyen @.***> wrote:

Hmm, if it's not too much to ask, would it be possible to share your project? Perhaps i can investigate the issue for you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Caldarie/flutter_tflite_audio/issues/19#issuecomment-949281394, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQKOTJUXFP3BTMCLBEAWFTDUIDTGLANCNFSM5GO2CYAQ .

Caldarie commented 3 years ago

That is no problem at all.

When sharing your repo, should i be aware of any Non Disclosure Agreements?

Caldarie commented 3 years ago

@andrejvujic Hi,

I may have come up with a solution to your problem. For some unknown reason, the tflite_audio plugin is unable to get the context of your app.

Perhaps we could bypass the request for permission from this plugin, and instead you could use this plugin to handle your permissions instead.

If you see no error with the permission_handler plugin, I can modify my code to bypass the permission check. Let me know your thoughts.