문제

I've spend all night, trying to get this to work, and it simply wont. I've got a physical tag, that my Windows Phone detects just right, however the SubscribeForMessage is never fired.

Using my Android device I can successfully read / write to the tag without any problems. I've even tried creating an app for my phone send out a message, using the following code:

Windows.Networking.Proximity.ProximityDevice proximityDevice;
long publishedMessageId = -1;
long subscribedMessageId = -1;

private void Button_Click_1(object sender, RoutedEventArgs e)
{
     proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

     if (proximityDevice != null)
     {
          publishedMessageId = proximityDevice.PublishMessage("Windows.Tietgen", "tietgen");
     }
}

Then I've copied the tag to the physical one, and the app is still not reacting on it, even though the phone is detecting the tag just fine... At this point I'm getting really frustrated.

This the code on my app:

if (ProximityDevice.GetDefault() != null)
{
     ProximityDevice device = ProximityDevice.GetDefault();
     subscribedMessageId = device.SubscribeForMessage("Windows.Tietgen", messagedReceived);
}

private void messagedReceived(ProximityDevice device, ProximityMessage m)
{
     MessageBox.Show("test");
}

What do I have to do, to get my phone to recognize the tag?

도움이 되었습니까?

해결책

I did it another way, and finally got it working!!! (Ironically right after I posted this question... :P)

I changed my write app to:

DataWriter writer = new DataWriter();
writer.WriteString("Test");

proximityDevice.PublishBinaryMessage("Windows:WriteTag.Tietgen", writer.DetachBuffer(), new MessageTransmittedHandler((pDevice, id) =>
{
    Debug.WriteLine("Message sent.");
}));

Then I just had to read it like this:

proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();
proximityDevice.SubscribeForMessage("Windows.Tietgen", new MessageReceivedHandler((proxDevice, message) =>
{
    Debug.WriteLine(message.DataAsString);
}));

And it worked :D

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top