Connect bluetooth scanner to Xamarin.Forms App - xamarin

I want to listen to a bluetooth barcode scanner input events in my Xamarin.Forms app targetted for iOS, Android and UWP.
I found a few GitHub like bluetoothLE, on how to list BLE devices with Xamarin for iOS or Android (it also says it is compatible with UWP), and some hints as to how to register to input, but I couldn't get it to work...
So I was thinking if there was a way to register to ALREADY PAIRED items (which are paired at OS level, before launching the app) and hook up to input events? Does anyone have some suggestions?

Related

how to get list of paired bluetooth devices that are power off or not is range in UWP

I want to get the list of paired devices that are not in range or power off. I am doing in Xamarin forms UWP
I want to get the list of paired devices that are not in range or power off. I am doing in Xamarin forms UWP
If you want to get the paired Bluetooth data from Xamarin platform side, we suggest you use DependencyService to approach, make device watcher in uwp client and callback the paired list data to Xamarin side.
For getting paired Bluetooth device. please refer official code sample here. For callback data with DependencyService please refer here.

Pairing issue when using SingleEntry (Android)

Socket Mobile SDK documentation states that the socket mobile scanner must be in "SPP" mode in order to work with the SingleEntry example. However, it seems that none of the Android phones i've tested recognize the device when in this mode for initial pairing. It does display in the paired devices list, connects to it fine, but does not fire any of the events (OnDeviceArrival, OnDecodedData, etc..) when a scan happens.
I can only get the SingleEntry example app to work with my Socket Mobile S800 by following the below steps (exactly):
Make sure scanner is in HID mode (default)
On my Android device, scan for pair-able devices. (the S800 displays with a keyboard icon)
Select the S800 device. (S800 does beep confirmation on connection)
Once the device is paired, un-pair it.
Change the S800 mode to "SPP" by scanning the appropriate code (recommended mode to work with Xamarin SingleEntry example)
Re-pair with the S800 device on my Android phone. (the S800 icon is now a desktop instead of a keyboard)
Open the "Socket EZ Pair" app, select pair using Bluetooth, select my S800 device from the list.
Now the OnDecodedData callback fires in the SingleEntry project.
What is the "Socket EZ Pair" app doing that i should be doing in my code to properly pair the device when in "SPP" mode?
Are there any better solutions for cross platform Bluetooth scanning? I'm particularly interested in just the OnScan (OnDecodedData) events...
UPDATE
The explanation is actually very simple. The SingleEntry Xamarin.Android app doesn't handle configuring the scanner for ScanAPI.
As you noted, after pairing the scanner you need to use EZ Pair before the scanner will be recognized by your app. This is because when you pair the scanner using Bluetooth settings, it creates an outgoing connection to the scanner, but ScanAPI listens for incoming connections. EZ Pair presents you with a list of paired Bluetooth devices, it connects to the one you select and configures that scanner to connect back before closing the connection.
The SingleEntry Android sample application includes the EZ Pair logic, but the Xamarin sample does not.
However, once you've used EZ Pair to configure your scanner to connect back, you should receive device arrival and decoded data notifications in the unmodified SingleEntry Xamarin.Android sample application.
Original answer
Not the solution, but good to check
Runtime permissions were introduced in Android 6.0 and SingleEntry has not been updated to check for the required permissions. Unfortunately, the file that sets the target framework is not checked in to git so fresh clones of the sample app now target newer versions than SingleEntry was designed for.
If you open Settings > Apps > Single Entry > Permissions and enable the storage permission, then it should start working.
The real fix is to check for WRITE_EXTERNAL_STORAGE and BLUETOOTH permissions before calling ScanApiHelper.Open() in your application.

Does Xamarin support to develop apps for Windows surface and how well?

I want to develop an app for Windows surface tablet and iOS mobile and iPad.
As I am a new user to Xamarin, when I created my first project,it shows 3 projects:-
hello.driod, hello.ios and hello.winPhone.
I have 3 questions based on this:-
How will I be able to write the same code and share for windows 8.1 and iOS?
and whenever I drag and drop the elements to the UI page, will the same elements be copied to both windows and iOS simultaneously or I got to add them seperately?
Currently I dont have a MAC to connect to my PC. Can I write the code and and there while testing it, connect it to a MAC or should it be connected during the whole process?
Please Help!
Using the same code depends on how your structure your app.
You can go the native route where you can share the bulk of your logic by containing it in a shared / PCL project (more on that here), but have platform specific code for your UI.
For example, if you have a cross platform app targeting iOS and Android you would still create the UI in a storyboard for iOS and AXML files for Android. Any code you want to "connect" to your UI would be specific to that platform as you would use the platform APIs. Any code that is not platform specific (i.e., not calling iOS or Android APIs) can go in your shared / PCL project.
Or you can choose Xamarin.Forms which adds a layer of abstraction by allowing you to write the UI in XAML once and have it work on all platforms. The advantage is increased code sharing as now your UI is also shared. The downside is to utilise platform specific features you'll need to implement DependencyService or custom renderers. Read more about Xamarin.Forms here.
As above, it depends. If you are going the native route, then no. If you are going with Xamarin.Forms, then you are using the same XAML code for the UI across platforms, but there is no drag and drop designer.
To build an iOS app you need to be connected to a Mac. You will also need to be connected to a Mac to use the iOS Designer.

Is it possible to create custom Android Wear notifications?

I have been doing lots of research trying to figure out if it is possible to create wear notifications with custom layouts over the past few months, but am struggling to find a solution.
I have tried to implement the following suggestions to no luck:
https://possiblemobile.com/2014/07/create-custom-ongoing-notification-android-wear/
http://android-wear-docs.readthedocs.org/en/latest/sync.html
Custom UI for Android Wear Notifications
Most of what I have read have instructed that in order to do this, I should create an android wear app with a data listener. The idea being the phone would send certain data to the watch (say a string) based on the type of notification it wants to send. I would disable the automatically generated wear notification. In its place, the Android Wear app listener would know what type of notification it is based on the string and display my custom pages for that notification instead.
My first problem I have run into is I have no idea how to debug code like this. Since in Android studio you can only launch the device app or the wear app, but not both at the same time.
The other question I have is, does the Android Wear app run in the background when the Device App is running? Do you have to open the Android Wear App first for the listener to be even working (if so then I guess this is not a solution to custom notifications)?
Is it actually possible to create custom layout android wear notifications?
If you want to use a custom layout for your notifications, you should create the notification on the watch, following Creating Custom Layouts. You can even make the custom notifications clickable, you can add actions that will open activities on the watch, etc.
For that, you can send a message from your phone to your watch and the listener implemented on your watch will receive it and then, create and display the notification using the correct layout corresponding to the message sent, for example.
In this case, the best way is to implement a WearableListenerService on your wearable. Its lifecycle is handled by the system which binds it only when necessary.
To debug, you install the wear app on the wear emulator or your watch, you install the mobile app on your phone and finally you connect the two following this tutorial if you're using the emulator or via bluetooth if you're using a watch (link in the tutorial).
The Android Wear app connects your phone to your watch, whether it is an emulator or not. So, in order for your message to be received, you must have connected wear and mobile via Android Wear. Then, once the connection is established, you don't necessarily need to keep it open. So yes, the Android Wear app runs in background.

How to start an app on the device with voice commands or by tapping on the icon in Android Wear Device?

In Android Wear it shows the notification and we can reply back through wearable device. But how to start any app from the Wearable device like voice input("Ok Google") or tap on the icon. Action should start from the wearable device not from mobile.
For Example to start my mobile's camera through Android Wear Device i will give voice input as "start Camera" and camera should start.
With the current preview-version of the SDK, this is not possible yet.
But looking at http://developer.android.com/wear/design/user-interface.html tells you, that this will possible using the "Cue Cards".
You can do this now! :)
With the release of the Wear SDK (API Level 20, Android 4.4W), you can now develop Wear applications with very much the same stack as standard Android apps (i.e. Activities, Services, Layouts, Views, &c).
There is also an API for communication, which for example Google Play Music uses to control media playback from the watch.Therefore, you could develop an application, installed both in the Wear device and in the handheld, to launch the phone's camera when started (by sending the command from the Wear activity).

Resources