Xamarin IOS bluetooth scan not showing all device list - xamarin

I am not getting all devices when I am trying to scan Bluetooth devices with my application. It does not show android and windows device list. I have attached screenshots to understand my problem.
Here is my code.
_centralManager = new CBCentralManager(DispatchQueue.CurrentQueue);
_centralManager.DiscoveredPeripheral += _centralManager_DiscoveredPeripheral;
_centralManager.UpdatedState += (object sender, EventArgs e) =>
{
var manager = sender as CBCentralManager;
if (manager.State == CBCentralManagerState.PoweredOn)
_centralManager.ScanForPeripherals(new CBUUID[0]);
};
Scan event:
public void _centralManager_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e)
{
var device = e.Peripheral;
var rssi = e.RSSI;
var ads = e.AdvertisementData;
}
Note: In my app, I was show device which name is not equal to null or blank.

I had implemented GATTA server on an Android device and it worked.
First, run the app on an Android device, start the server and done.
https://github.com/androidthings/sample-bluetooth-le-gattserver/blob/master/java/app/src/main/java/com/example/androidthings/gattserver/GattServerActivity.java
In my case, I wanted to do this for android things. So I implemented the code in android things.

Related

Progress Dialog not rotating in xamarin android os 7

I am using ZXing nuget for scan QR code in my Xamarin Android application. I have added loader after scanned. I am calling api based on scanned data. But api takes time. I had written code for display loader it's not displaying properly on android 8 or android 9. But it's not rotating in android 7. What's wrong with my code?
My code is :
serverProgressDialog = new ProgressDialog(this);
serverProgressDialog.SetProgressStyle(ProgressDialogStyle.Spinner);
serverProgressDialog.SetMessage("Contacting server. Please wait...");
serverProgressDialog.Indeterminate = true;
serverProgressDialog.SetCancelable(false);
serverProgressDialog.Create();
serverProgressDialog.ShowEvent += ServerProgressDialog_ShowEvent;
For show :
internal void ShowServerProgressDialog()
{
serverProgressDialog.Show();
}
On ScanButton Click code :
imageBtn.Click += async delegate
{
scanner.AutoFocus();
var result = await scanner.Scan(options);
scanner.Cancel();
if (result != null)
{
SetTextboxValue(result.Text);
new Handler().PostDelayed(new Runnable(() =>
ShowServerProgressDialog()), 10);
}
else
{
HideServerProgressDialog();
}
};
On event show I am displaying dialog. Some how it's not rotating on android device os version 7.

Xamarin WebView download file under authentication in iOS

I am developing a Xamarin Forms application which is basically a WebView where the user have access to some files which is supposed the user have to be able to download.
To achieve this in Android, I have this CustomRenderer for the WebView in the Android project, basically I get the cookies (files are under authentication) to send them to the DownloadManager:
public class CustomWebViewRenderer : WebViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var customWebView = Element as CustomWebView;
Control.Settings.AllowContentAccess = true;
Control.Settings.AllowUniversalAccessFromFileURLs = true;
Control.Settings.DomStorageEnabled = true;
Control.Settings.JavaScriptEnabled = true;
Control.Download += OnWebViewDownload;
}
}
private void OnWebViewDownload(object sender, DownloadEventArgs e)
{
var source = AUri.Parse(e.Url);
var request = new DownloadManager.Request(source);
request.AllowScanningByMediaScanner();
var cookieString = CookieManager.Instance.GetCookie(e.Url);
request.AddRequestHeader("Cookie", cookieString);
request.AddRequestHeader("User-Agent", e.UserAgent);
request.SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted);
request.SetDestinationInExternalPublicDir(AEnvironment.DirectoryDownloads, source.LastPathSegment);
var manager = (DownloadManager)MainActivity.Current.GetSystemService("download");
manager.Enqueue(request);
}
}
The download starts in the background and everyone is happy.
My problem started when I noticed that this behavior is not available in iOS, since the file is displayed on the webview not giving me any option to download or showing the "Open in..." dialog. In plus, after trying to implement a CustomRenderer for the iOS platform too, I see no handler, property or method in the UIWebView or the WKWebView which allows me to manage the download or share the file in another app.
I need to be able to download the file in iOS, or at least, show the "Open in" bar. Any suggestions? Thanks in advance.

BluetoothLEAdvertisementWatcher doesn't work

I have Windows 10 Pro, build 10586.494 on HP ZBook G2. When I go to Settings -> Devices -> Bluetooth and switch on Bluetooth, I can see nearby BLE devices (they are custom made BLE devices manufactured by my company).
I want to interact with my BLE devices in Universal Windows application (in Visual Studio 2015). I use this code (it is just a snippet of code)
BluetoothLEAdvertisementWatcher watcher;
//....
watcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active };
watcher.Received += WatcherOnReceived;
watcher.Start();
//....
private void WatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs btAdv)
{
}
When I run this application, WatcherOnReceived is never executed (although watcher.Start was executed). Why and how to fix it?
If found a better workaround for this. (I'm using Win 10 1803.)
First, to recap the problem since the original question is not entirely clear about it:
BluetoothLEAdvertisementWatcher works if BLE device is advertising before watcher.Start()
BluetoothLEAdvertisementWatcher does not work if BLE device starts advertising after watcher.Start()
If BluetoothLEAdvertisementWatcher is not working after watcher.Start(), it will begin working when Windows 10 Bluetooth Settings is opened or closed (i.e. the opening or closing of the settings window triggers BluetoothLEAdvertisementWatcher to start working)
So, the workaround I came up with is to keep starting and stopping a second BluetoothLEAdvertisementWatcher in the background to create the same sort of trigger that the Windows Bluetooth Settings window provides.
For example, using a WinForms timer:
...
var timer = new Timer { Interval = 1000 };
timer.Tick += Timer_Tick;
timer.Start();
...
private void Timer_Tick(object sender, EventArgs e)
{
var watcher = new BluetoothLEAdvertisementWatcher();
watcher.Received += (s, a) => { };
watcher.Start();
Task.Delay(500).ContinueWith(_ => watcher.Stop());
}
I have to keep Bluetooth switched on in Settings -> Devices -> Bluetooth in order to receive advertisements in my app.

Launch Cordova Windows App with Parameters

Am finding hard to launch Cordova Windows App, from another native Windows App.
Using Protocol invocation, I am passing few parameters to Cordova Windows App, to see if the Cordova app identifies those parameters from the Windows Native App.
Is there anyway to pass Parameters from native Windows App to Cordova App, so that Cordova App identifies the parameters as arguments?
In native windows 8 store app I am using app protocol association to send parameters one app to another app. like
in sender app:
mainpage.xaml.cs on button click
var url = "apptest:?" + name;
Uri uri = new Uri(url);
await Launcher.LaunchUriAsync(uri);
in received app
Package.appxmanifest:
Declarations --> available declarations add --> protocol --> name = apptest
app.xaml.cs
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs protocolArgs = args as ProtocolActivatedEventArgs;
var rootFrame = new Frame();
rootFrame.Navigate(typeof(MainPage), protocolArgs);
Window.Current.Content = rootFrame;
}
Window.Current.Activate();
}
mainpage.xaml.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ProtocolActivatedEventArgs pa = e.Parameter as ProtocolActivatedEventArgs;
if(pa != null)enter code here
{
string qS = pa.Uri.Query;
if (!string.IsNullOrEmpty(qS))
{
Txt_name.Text = qS;
}
}
}
in this way i will take the data from sender app.
Same like is there any way to receive data from windows 10 native app to cordova app. it is very hard to find the solution. not able to find the exact piece of code.

How to get the BLE advertisement (GAP) scanrecord in Xamarin with Monkey.Robotics to extract additional information to the device name?

We want to extract more than the device name from a BLE advertisement with Xamarin using the Monkey.Robotics framework.
This excerpt of the BLEExplorer example gets a Device, which provides a string containing the device name:
adapter.DeviceDiscovered += (object sender, DeviceDiscoveredEventArgs e) => {
Device.BeginInvokeOnMainThread(() => {
devices.Add (e.Device);
});
};
We like to know if there is a way to get to the full payload of the GAP advertisement?

Resources