通过nfc共享图像并存储到数据库中

时间:2013-06-25 15:18:10

标签: c# windows-phone-8 nfc

如何通过nfc共享图像并将其存储到数据库中?我查看了这个website并且只设法创建了对等连接。至于分享图片,我遇到了这篇文章并尝试运行demo,但我无法理解任何代码。有没有更简单的方法来做到这一点?

到目前为止我做了什么:

 public ExchangeCard()
    {
        InitializeComponent();
        ProximityDevice device = ProximityDevice.GetDefault();

        // Make sure NFC is supported
        if (device != null)
        {
        PeerFinder.TriggeredConnectionStateChanged += OnTriggeredConnectionStateChanged;

            // Start finding peer apps, while making this app discoverable by peers
            PeerFinder.Start();
        }

    }



    StreamSocket _streamSocket;

    void OnTriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
    {
        switch (args.State)
        {
            case TriggeredConnectState.Listening:
                // Connecting as host
                break;
            case TriggeredConnectState.PeerFound:
                // Proximity gesture is complete and user can pull their devices away. Remaining work is to 
                // establish the connection using a different transport, like TCP/IP or Bluetooth
                break;
            case TriggeredConnectState.Connecting:
                // Connecting as a client
                break;
            case TriggeredConnectState.Completed:
                // Connection completed, retrieve the socket over which to communicate
                _streamSocket = args.Socket;
                break;
            case TriggeredConnectState.Canceled:
                break;
            case TriggeredConnectState.Failed:
                // Connection was unsuccessful
                break;
        }
    }

2 个答案:

答案 0 :(得分:0)

查看符合您要求的示例:http://code.msdn.microsoft.com/wpapps/PixPresenter-Code-sharing-39ed631f

基本上,我们的想法是使用PeerFinder(就像你开始时那样),然后在两个对等体之间打开Socket。相关代码位于PeerConnector.cs

答案 1 :(得分:0)

不幸的是,NFC变得复杂。为了无缝地处理点对点通信,需要进行相当多的管道工作。在网站上回答这个问题太过分了,所以我不得不求助于链接。

您可以查看此诺基亚文章和项目,了解您对管道的理解。 http://developer.nokia.com/Resources/Library/Lumia/#!code-examples/nfc-talk.html

然后,您可以查看本文以添加图像传输功能。 http://developer.nokia.com/Community/Wiki/Transfer_an_Image_with_NFC