Home > Software engineering >  Why can't I use "this" in my Android Studio plug-in for Unity?
Why can't I use "this" in my Android Studio plug-in for Unity?

Time:12-04

I'm doing a plug-in on android studio for unity, I want to do text recognition to an image and send a string of the text detected to unity I have the plugin in the unity project and can send and receive information normally, I want to use the google vision library, but the problem is the class TextRecognizer that I'm using, when it's built it asks for a "context", the guide says you have to use "this" but it seems that the whole plug-in structure doesn't go with it, I don't know what to do anymore

enter image description here

The problem description is: 'Builder(android.content.Context)' in 'com.google.android.gms.vision.text.TextRecognizer.Builder' cannot be applied to '(com.cwgtech.unity.MyPlugin)'

The name of the project comes from the youtube tutorial I was following to create the plug-in

I've followed the Android-Studio recommended action of making my plug-in class extend android.content.context, but it creates a lot of other functions on the top of my code that I don't understand, and all of them have this error: Must be one of: PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_DENIED

CodePudding user response:

The problem is that the Google Vision library requires an Android Context object in order to be used. Unfortunately, your Unity Android plugin doesn't provide an Android Context object. You can try creating an Android Context object within your plugin and passing it to the Google Vision library, but this may not work. Alternatively, you could look into using the Google Mobile Vision library which doesn't require an Android Context object.

  • Related