Hi!
At first I want say, that I made many things with C#, but don't have much experience in Xamarin. So please don't kill me if my question is silly. Image may be NSFW.
Clik here to view.
I have just tried to add NFC in my a Xamarin App. I did it it like there: forums.xamarin.com/discussion/34007/read-information-from-uncontact-card-using-nfc-techonology-on-xamarin
I have written the code nearly exactly like in this post and also created a file named xml under Resources with techlist.xml in it. It all workde fine and I have installed the App on my phone, but I couldn'T open it. I found the App in the App-List, but there wasn't a way to open it. When I tried to launch it in the Android Emulator the App just didn't open. If you need more information please contact me. Thank you very much!
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Nfc;
using System.Text;
namespace NFC
{
[Activity(Label = "NFC", MainLauncher = false), IntentFilter(new[] { "android.nfc.action.TECH_DISCOVERED"
},
Categories = new[] {
"android.intent.category.DEFAULT"
})]
[MetaData("android.nfc.action.TECH_DISCOVERED", Resource =
"@xml/techlist")]
public class TransactionActivity : Activity
{
protected string TagUid;
protected override void OnResume()
{
base.OnResume();
SetContentView(Resource.Layout.Main);
TextView idtext = FindViewById<TextView>(Resource.Id.textView1);
if (NfcAdapter.ActionTechDiscovered.Equals(Intent.Action))
{
var MyTag = Intent.GetParcelableExtra(NfcAdapter.ExtraTag) as Tag;
if (MyTag != null)
{
var tagId = MyTag.GetId();
TagUid = ByteArrayToString(tagId);
idtext.Text = TagUid;
}
}
}
private static string ByteArrayToString(byte[] ba)
{
var hex = new StringBuilder(ba.Length * 2);
foreach (byte b in ba)
hex.AppendFormat("{0:x2}", b);
return hex.ToString();
}
// public class MainActivity : Activity
// {
// protected override void OnCreate(Bundle savedInstanceState)
// {
// }
// }
}
}