Hello,
Welcome to our Microsoft Q&A platform!
Is it possible to inheritace the SpeechRecognizer class in Xamarin
No, we cannot create a class to extend the SpeechRecognizer class. When creating the custom class, it requires to add the constructor method like below:
public class TestSpeechRecognizer : SpeechRecognizer
{
protected TestSpeechRecognizer(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}
}
In above code, we can see that the constructor will call the SpeechRecognizer's constructor method. Xamarin.Android is only a layer of wrapper for Android native libraries. In native Android's source code, SpeechRecognizer class only privdes the private
constructor method which cannot be accessed just like the error describes.
//the part source code of the SpeechRecognizer class
private SpeechRecognizer(final Context context, final ComponentName serviceComponent)
{
mContext = context;
mServiceComponent = serviceComponent;
}
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.