protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     var device = ProximityDevice.GetDefault();
     if (device == null) return;
     var record = new NdefSpRecord {
         Uri = "cloudsdale://clouds/" + cloud.id,
         NfcAction = NdefSpActRecord.NfcActionType.DoAction
     };
     record.AddTitle(new NdefTextRecord { Text = cloud.name, LanguageCode = "en" });
     var message = new NdefMessage { record };
     messageIds.Add(device.PublishBinaryMessage("NDEF", message.ToByteArray().AsBuffer()));
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            // Dynamically construct some more NDEF records
            var spRecord = new NdefSpRecord
            {
                Uri = "http://andijakl.github.io/ndef-nfc/",
                NfcAction = NdefSpActRecord.NfcActionType.DoAction
            };
            spRecord.AddTitle(new NdefTextRecord { LanguageCode = "en", Text = "NFC Library" });
            spRecord.AddTitle(new NdefTextRecord { LanguageCode = "de", Text = "NFC Bibliothek" });
            NfcRecords.Add("SmartPoster", spRecord);

            // Ensure the path exists
            var tagsDirectory = Path.Combine(Environment.CurrentDirectory, FileDirectory);
            Directory.CreateDirectory(tagsDirectory);

            // Write tag contents to files
            foreach (var curNdefRecord in NfcRecords)
            {
                WriteTagFile(tagsDirectory, curNdefRecord.Key, curNdefRecord.Value);
            }

            // Multi-record file
            var record1 = new NdefUriRecord {Uri = "http://www.twitter.com"};
            var record2 = new NdefAndroidAppRecord {PackageName = "com.twitter.android"};
            var twoRecordsMsg = new NdefMessage {record1, record2};
            WriteTagFile(tagsDirectory, "TwoRecords", twoRecordsMsg);

            var record3 = new NdefRecord
            {
                TypeNameFormat = NdefRecord.TypeNameFormatType.ExternalRtd,
                Type = Encoding.UTF8.GetBytes("custom.com:myapp")
            };
            var threeRecordsMsg = new NdefMessage { record1, record3, record2 };
            WriteTagFile(tagsDirectory, "ThreeRecords", threeRecordsMsg);

            // Success message on output
            Console.WriteLine("Generated {0} tag files in {1}.", NfcRecords.Count, tagsDirectory);
            Debug.WriteLine("Generated {0} tag files in {1}.", NfcRecords.Count, tagsDirectory);
        }
Beispiel #3
0
 void HandleClicked(object sender, EventArgs e)
 {
     var spRecord = new NdefSpRecord
     {
         Uri = "www.poz1.com",
         NfcAction = NdefSpActRecord.NfcActionType.DoAction,
     };
     spRecord.AddTitle(new NdefTextRecord
     {
         Text = "NFCForms - XamarinForms - Poz1.com",
         LanguageCode = "en"
     });
     // Add record to NDEF message
     var msg = new NdefMessage { spRecord };
     try
     {
         device.WriteTag(msg);
     }
     catch (Exception excp)
     {
         DisplayAlert("Error", excp.Message, "OK");
     }
 }
Beispiel #4
0
 void HandleClicked(object sender, EventArgs e)
 {
     var spRecord = new NdefSpRecord
     {
         NfcAction = NdefSpActRecord.NfcActionType.DoAction,
     };
     spRecord.AddTitle(new NdefTextRecord
         {
             Text = "00001:5.49"
         });
     // Add record to NDEF message
     var msg = new NdefMessage { spRecord };
     try
     {
         device.WriteTag(msg);
     }
     catch (Exception excp)
     {
         DisplayAlert("Error", excp.Message, "OK");
     }
 }