UWP - How to get device model - c#

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.

Related

Android Bluetooth Device List - Friendly Names

(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.

Windows 8.1 WPF application mixerSetControlDetails returns MMSYSERR_ERROR

Edit
After modifying the NAudio source code and a little debugging, I found that the mixerSetControlDetails function, which is called when I set the Value property, returns MMSYSERR_ERROR.
Is there a way to get further information about why mixerSetControlDetails failed?
I'm also open to other ways to accomplish same thing on C#.
Original
I have some code that computes energy in voice and sets the microphone boost level according to this computed value using NAudio. I have no problem reading audio samples but when I try to set microphone boost, the program gets stuck.
I have checked the issue on Windows 7, 8, and 8.1. The problem occurs only on Windows 8.1. Interestingly when I run the program on a virtual machine with Windows 8.1 it works as expected. Can this be a permission problem?
Here is the code for setting the boost value
foreach (MixerControl mixerControl in MixerLine.Controls)
{
if (mixerControl.ControlType == MixerControlType.Volume)
{
UnsignedMixerControl volumeControl = (UnsignedMixerControl)mixerControl;
volumeControl.Value = (uint) value;
}
}
Where MixerLine is created beforehand with this code.
MixerLine = new MixerLine((IntPtr) deviceID, 0, MixerFlags.WaveIn);
It seems the mixerSetControlDetails function returns MMSYSERR_ERROR randomly (at least I couldn't find a pattern). Actually it does set the new value, just ignore the exception, or if it does not set try setting the value again. The stuck behavior was about my program, irrelevant to this error.

Getting P6083 as model name for nokia lumia 625 using PnpObject Device Container

I am developing one application and want model name on which my app would be running. I am using WinRT for development. But below code gives me P6083 as Model Name.
var pnp = await PnpObject.CreateFromIdAsync(PnpObjectType.DeviceContainer, "{00000000-0000-0000-FFFF-FFFFFFFFFFFF}", new[] { "System.Devices.ModelName" });
var deviceName=" + (string)pnp.Properties["System.Devices.ModelName"];
Can anyone help on these
Look at the EasClientDeviceInformation type - it is easier to use. But these return internal product names, not marketing names (which can differ by geography / carrier / etc).

Get MAC address of device

I'm writing a Windows Phone 8.1 Application that discovers nearby Bluetooth Low Energy devices.
foreach (DeviceInformation device in devices)
{
BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(device.Id);
}
Everything works fine, but the bleDevice.BluetoothAddress property contains a ulong type, while I need a string type, formatted like a Mac Address.
Example:
bleDevice.BluetoothAddress: 254682828386071 (ulong)
Desired Mac Address: D1:B4:EC:14:29:A8 (string) (that's an example of how I need it, not the actual Mac Address of the device)
Is there a way to convert the long to a Mac Address? Or is there another way to directly discover the Mac Address without conversions? I know there's a tool named In The HAnd - 32feet that could help me, but as of now Windows Phone 8.1 is not supported.
There are numerous topics you can find through Google and here on StackOverflow. Anyway, here's one way to do it:
ulong input = 254682828386071;
var tempMac = input.ToString("X");
//tempMac is now 'E7A1F7842F17'
var regex = "(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})";
var replace = "$1:$2:$3:$4:$5:$6";
var macAddress = Regex.Replace(tempMac, regex, replace);
//macAddress is now 'E7:A1:F7:84:2F:17'

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