Android Bluetooth Device List - Friendly Names - c#

(Cross posted from https://forums.xamarin.com/discussion/116840/android-bluetooth-device-list-friendly-names)
I have this C# method for Android to get a list of paired Bluetooth devices:
public List<string> PairedDevices()
{
var adapter = BluetoothAdapter.DefaultAdapter;
var devices = new List<string>();
foreach (var bd in adapter.BondedDevices)
{
devices.Add(bd.Name);
}
return devices;
}
Which works fine, except I need the list to show the same name as what shows on the list of devices that is displayed to users in the Android Bluetooth settings. If the user has renamed a device, the new name is not listed in the "Name" property. Name still contains the original name of the device before the user renamed it.
I'm new to Android development. I'm seeing some references to ExtraDevice and ExtraName but am not sure if this is what I need or how to obtain it. Help?
PS: am using a Xamarin Forms PCL solution, and the above method is part of a Dependency class borrowed from here: https://acaliaro.wordpress.com/2017/02/07/connect-a-barcode-reader-to-a-xamarin-forms-app-via-bluetooth/.

#Salman-Nasseem basically answered this in their comment. It turns out my question is misguided. If the user renamed a bluetooth device, the actual device name has not changed.

Related

C# - Bluetooth LE DevicePicker with Custom Filter

I'm trying to add a custom filter to my DevicePicker using System.ItemNameDisplay
I've been searching the internet, finding examples, and testing different implementations but nothing has worked
I can use any of the built in DeviceSelectors from the BluetoothLEDevice class and they work fine but for my specific application I need the DevicePicker to only show devices whose name starts with a certain string [ProductNameStart] where [ProductNameStart] is a hard-coded string representing the starting characters of the devices I want to include on the DevicePicker
I've looked through this example (specifically Scenario 6) and it claims that the AQS can be used in the DevicePicker but doesn't show how.
I also created another project using DeviceWatcher and that works exactly like I intended using this constructor
string deviceFilter = "System.ItemNameDisplay:~<\"[ProductNameStart]\"";
string[] rp = { };DeviceWatcher deviceWatcher = DeviceInformation.CreateWatcher(deviceFilter,rp,DeviceInformationKind.AssociationEndpoint);
I've tried the following implementations for DevicePicker with no luck
DevicePicker devicePicker = new DevicePicker();
//devicePicker.RequestedProperties.Add("System.ItemNameDisplay"); // Doesn't help anything
//devicePicker.Filter.SupportedDeviceSelectors.Add("System.ItemNameDisplay:~<\"[ProductNameStart]\""); // Doesn't Work
//devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromDeviceName("System.ItemNameDisplay:~<\"[ProductNameStart]\"")); // Doesn't Work
//devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromDeviceName("[ProductNameStart]")); // Doesn't Work
//devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromDeviceName(":~<\"[ProductNameStart]\"")); // Doesn't Work
//devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromDeviceName("~<\"[ProductNameStart]\"")); // Doesn't Work
//devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromDeviceName("\"[ProductNameStart]\"")); // Doesn't Work
Resources:
SO Posts:
Bluetooth LE Enumeration with DevicePicker issue
AQS syntax when providing a filter for BLE scanning in UWP
Other Posts:
Displaying the device picker in a UWP application
Build a device selector
Using Advanced Query Syntax Programmatically
UWP: Working with Bluetooth devices (part 1)

Why does StoreContext.GetStoreProductsAsync(productKinds, storeIDs) get only current UWP app?

I have another UWP question.
I'm trying to get all the UWP apps that I published on the MS Store, but it seems there is something wrong: I can only get the current one beeing executed, although I insert many store IDs, the ones from my apps, as suggested by MS Docs.
Here's the code (of course, in my code I insert the real IDs):
StoreContext context = StoreContext.GetDefault();
string[] productKinds = { "Application" };
List<String> filterList = new List<string>(productKinds);
string[] storeIds = { "firstID", "secondID", "thirdID" };
StoreProductQueryResult queryResult = await context.GetStoreProductsAsync(filterList, storeIds);
if (queryResult.ExtendedError == null)
{
foreach (var product in queryResult.Products)
{
// Do something with 'product'
}
}
Well, it only returns one item, the current one.
Is there a way to obtain even other store apps?
Am I doing something wrong?
Thanks a lot.
GetStoreProductsAsync is only for the products associated with the app (i.e. add-ons):
Gets Microsoft Store listing info for the specified products that are
associated with the current app.
[docs]
To solve the problem you might want to look in the direction of Microsoft Store collection API and purchase API (requires web app setup in Azure).
Other than that StoreContext class at its current state doesn't contain API to get product information about other apps and their add-ons.

UWP - How to get device model

I need to know my device model when my app running.
I try many ways to get that like:
string[] properties = { "System.Devices.ModelName"}; await PnpObject.FindAllAsync(PnpObjectType.DeviceContainer, properties);
or new EasClientDeviceInformation().SystemProductName;
But both never return my device model, like Lumia 640. On desktop it works fine but on mobile not.
Any ideas to solve my problem?
Thanks
Lumia Models are not the actual Model Names. For example my Lumia 640 is RM-1073. But one of my friend who uses a Carrier Locked Lumia 640 phone model is RM-1072.
You can get this info using
var clientDeviceInformation = new EasClientDeviceInformation();
string systemProductName = clientDeviceInformation.SystemProductName;
There is a way to receive Lumia Model Number too. If the phone's Name is never changed, it will still have the original Name. You can retrieve that using
string friendlyName = clientDeviceInformation.FriendlyName;
However there might be very few people who does not change their phone's name.

Where do I find the name displayed in "Devices and Printers"

I have a serial device connected via Bluetooth. It shows up nicely on COM4. I can communicate with it without a problem.
I want to make it simpler for the user to locate (ideally, I'll auto-detect it), so I want to find it by name. In the "Devices and Printers" list, I get a valid name, which is perfect. However, I can't seem to find that value programatically. I've tried a ton of stuff using the "ManagementObjectSearcher" class, including listing out all the Properties and SystemProperties, but no values match the name displayed in "Devices and Printers".
If I look in the "Device Manager" list, it just shows "Standard Serial over Bluetooth link (COM4)", which is not useful for identifying it, obviously.
So how the heck to I get the displayed name in the "Devices and Printers" list?
is this what you're looking for?
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printersettings.installedprinters(v=vs.110).aspx
So, I found a solution. I grabbed the library from these guys:
http://32feet.codeplex.com/
Using that library, added these 2 lines:
BluetoothClient client = new BluetoothClient();
BluetoothDeviceInfo[] devices = client.DiscoverDevices();
That gave me the device "DeviceName" (the name I was after) and "DeviceAddress" (a chunk of the device id, basically).
I then queried the system using the "ManagementObjectSearcher", which gave me a list of COM ports and device IDs (System.Management namespace).
ConnectionOptions options = ProcessConnection.ProcessConnectionOptions();
ManagementScope connectionScope = ProcessConnection.ConnectionScope(Environment.MachineName, options, #"\root\CIMV2");
ObjectQuery objectQuery = new ObjectQuery("SELECT * FROM Win32_PnPEntity");
ManagementObjectSearcher comPortSearcher = new ManagementObjectSearcher(connectionScope, objectQuery);
...etc as I looped over the results, pulled out the COM ports, and so on
I mapped the device IDs from the "ManagementObject" values back to the "devices" list, merged the results, and ended up with something that had the name, device id, a flag indicating if it was a bluetooth device, and the "human readable" name from the bluetooth device, if it existed.
Painful, but it works fairly well. It's slow (client.DiscoverDevices() takes awhile), but that's survivable in my case.

Get list of audio devices and select one using c#

Hi I am creating a desktop based application in windows using C#.
I have to show list of all available audio & video devices in 2 different combo boxes.
Selecting any device from combo box will set that particular device as the default one
I am using WMI.
Code to get list of available audio devices:
ManagementObjectSearcher mo =
new ManagementObjectSearcher("select * from Win32_SoundDevice");
foreach (ManagementObject soundDevice in mo.Get())
{
String deviceId = soundDevice.GetPropertyValue("DeviceId").ToString();
String name = soundDevice.GetPropertyValue("Name").ToString();
//saving the name and device id in array
}
if i try to set the device like this:
using (RegistryKey audioDeviceKey =
Registry.LocalMachine.OpenSubKey(audioDevicesReg
+ #"\" + audioDeviceList.SelectedText.ToString(), true)){}
i get exception :
System.Security.SecurityException occurred in mscorlib.dll
Now I have few questions:
1) How to set the selected device as the default audio device?
2) The array contains device name as : "High Definition audio device"
even when I have attached a headset.
3) I want the list as speaker,headset etc...How to get that?
can anybody point me in the right direction?
There is no documented mechanism for changing the default audio device.
That's because you're enumerating the physical audio devices, not the audio endpoints.
You want to use the IMMDeviceEnumerator API to enumerate the audio endpoints (speakers, etc).
Unfortunately there is no managed interop published by Microsoft for the IMMDeviceEnumerator API, you'll need to define your own (there are several definitions available on the internet).
I am answering too late to this question.. but it may be helpful for others.
Lync 2013 SDK provides DeviceManager class which list all the audio and video devices in collections
LyncClient.GetClient().DeviceManager.AudioDevices enumerates all the audio devices on the system
LyncClient.GetClient().DeviceManager.VideoDevices enumerates all the video devices on the system
So, one can set the device as:
LyncClient client = LyncClient.GetClient();
DeviceManager dm = client.DeviceManager;
dm.ActiveAudioDevice = (AudioDevice)dm.AudioDevices[0]; //or any other found after foreach
dm.ActiveVideoDevice = (VideoDevice)dm.VideoDevices[0]; //or any other found after foreach
HTH.

Categories

Resources