locked
Launching app on another device using Proximity

    Question

  • private void PublishLaunchAppMessageToDevice()
            {
                if (proximityDevice == null)
                    proximityDevice = ProximityDevice.GetDefault();
    
                proximityDevice.DeviceArrived += device_DeviceArrived;
                proximityDevice.DeviceDeparted += device_DeviceDeparted;
                string args = "user=default";
                string platform = "WindowsPhone";
                string appId = '{' + Windows.ApplicationModel.Store.CurrentApp.AppId.ToString() + '}';
                string launchAppMessage = String.Format("{0}\t{1}\t{2}", args, platform, appId);
    
     using (Windows.Storage.Streams.DataWriter dataWriter = new Windows.Storage.Streams.DataWriter())
                {
                    dataWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE;
                    dataWriter.WriteString(launchAppMessage);
      
                    publishedMessageId = proximityDevice.PublishBinaryMessage("LaunchApp:WriteTag", dataWriter.DetachBuffer(),
                        msgHandler);
                }
    }
    void msgHandler(ProximityDevice d, long id) {
    //Meesage
    } 
    void device_DeviceDeparted(ProximityDevice sender)
            {
               gobject.Dispatcher.BeginInvoke(() =>
                {
                  MessageBox.Show("NFC device departed");
               });
            }
     void device_DeviceArrived(ProximityDevice sender)
            {
                gobject.Dispatcher.BeginInvoke(() =>
                { 
                  MessageBox.Show("NFC Device Arrived");
                });
            }
    
    Not able to launch app on another device. The device Arrived and Departed message appears. Both devices have NFC.
    Monday, May 12, 2014 12:16 PM

Answers

All replies