Xamarin.Android Machine Name Blank for Uncaught Exceptions
Martin Kirsten
Posted on
Oct 24 2014
Hi
Uncaught exceptions in my Xamarin.Android app have the Machine Name set to Blank - is there some way I can set this to the actual device name? (this works automatically in the Xamarin.iOS version of the same app).
Thanks
Jason Fauchelle
Raygun
Posted on
Oct 28 2014
Hi Martin,
In the first version of the Xamarin Android provider, we did set the Machine name. The only way I know of doing this is to get the name from the BluetoothAdapter class. Unfortunately this requires Bluetooth permissions to be set on Raygun users applications which is not desired and so we decided to remove it, but kept the MachineName property to be consistent with other Raygun providers and so that you can set it manually.
To set this, first enable Bluetooth permissions in your application by placing this in the AssemblyInfo:
-[assembly: UsesPermission(Android.Manifest.Permission.Bluetooth)]
Then attach an event handler to the SendingMessage event of a RaygunClient instance. (If you are calling the Attach method, you can get the static RaygunClient instance via RaygunClient.Current. Then your event handler could be like this to set the MachineName:
private void RaygunClient_SendingMessage(object sender, RaygunSendingMessageEventArgs e)
{
BluetoothAdapter adapter = BluetoothAdapter.DefaultAdapter;
e.Message.Details.MachineName = adapter == null ? "Unknown" : adapter.Name;
}
If you know of a better way to get the device name without Bluetooth permissions, we'd love to get this working automatically in the Xamarin-Android provider. We'll also have another look at if this can be improved.
Please let me know if you have further questions about this.
-Jason Fauchelle