Skip to content

Commit

Permalink
Try connect to obd device in the beginning to avoid the "called at an…
Browse files Browse the repository at this point in the history
… unexpected time" issue
  • Loading branch information
xiangyan99 committed Apr 25, 2016
1 parent 483ead1 commit e6ddd8a
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
using Windows.UI.Xaml.Navigation;
using MyDriving.ViewModel;
using MyDriving.Utils;
using Windows.Devices.Enumeration;
using Windows.Devices.Bluetooth.Rfcomm;

namespace MyDriving.UWP.Views
{
Expand Down Expand Up @@ -151,6 +153,18 @@ void OnPropertyChanged(object sender, PropertyChangedEventArgs e)

private async Task StartTrackingAsync()
{
// Request permission to access bluetooth
try
{
DeviceInformationCollection deviceInfoCollection =
await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
if (deviceInfoCollection.Count() > 0)
{
DeviceInformation device = deviceInfoCollection[0];
await RfcommDeviceService.FromIdAsync(device.Id);
}
}
catch (Exception) { }
// Request permission to access location
var accessStatus = await Geolocator.RequestAccessAsync();

Expand Down

0 comments on commit e6ddd8a

Please sign in to comment.