Dear all,
I am a beginner in Xamarin and I am trying to develop my first Android app.
I have to use a third party SDK to connect and receive data from a barcode scanner via bluetooth.
I created a new Xamarin.Forms project and a new Library binding android project.
I followed the poor documentation for the SDK but when I call a function which should search for bluetooth devices, I get this error:
{Java.Lang.IllegalStateException: Check whether the service is registered in the AndroidManifest
at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <286213b9e14c442ba8d8d94cc9dbec8e>:0
at Android.Runtime.JNIEnv.CallVoidMethod (System.IntPtr jobject, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in <b781ed64f1d743e7881ac038e0fbdf85>:0
at Com.Bim.Bluetooth.Manager.SearchScanner (Com.Bim.Interfaces.IOnSearchCallback onSearchCallback) [0x0005c] in C:\ProgettiVS\TestJar\PosunitechScanner\obj\Debug\generated\src\Com.Bim.Bluetooth.Manager.cs:248
at TestJar.Droid.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00031] in C:\ProgettiVS\TestJar\TestJar\TestJar.Android\MainActivity.cs:43
--- End of managed Java.Lang.IllegalStateException stack trace ---
java.lang.IllegalStateException: Check whether the service is registered in the AndroidManifest
at com.bim.bluetooth.Manager.checkBinder(Manager.java:117)
at com.bim.bluetooth.Manager.searchScanner(Manager.java:46)
at md59d3085c099eda7a3b5de2c6cfaef6eaa.MainActivity.n_onCreate(Native Method)
at md59d3085c099eda7a3b5de2c6cfaef6eaa.MainActivity.onCreate(MainActivity.java:29)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3054)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1814)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:280)
at android.app.ActivityThread.main(ActivityThread.java:6706)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
}
This is my Manifest, as suggested in the documentation I added permissions and enabled the service.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="-----schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.TestJar.Android">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="27" />
<application android:label="TestJar.Android">
<service
android:name="com.bim.bluetooth.BluetoothService"
android:enabled="true" />
</application>
</manifest>
Is the error related to the com.bim.bluetooth.BluetoothService service?
Did I register the service in the right way?
I have a test project if you want to see it, just ask me.
Thank you in advance
Fabio