Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android NFC和Xamarin,什么都没发生_Android_Xamarin.android_Tags_Xamarin.forms_Nfc - Fatal编程技术网

Android NFC和Xamarin,什么都没发生

Android NFC和Xamarin,什么都没发生,android,xamarin.android,tags,xamarin.forms,nfc,Android,Xamarin.android,Tags,Xamarin.forms,Nfc,这是第一次,我想为WinPhone和Android项目跨平台实现NFC到Xamarin.Forms 我在Android上测试我的应用程序,但什么都没发生。 作为一个工具,我使用了Visa Pay Wave卡,我在Android程序reTag中测试了该卡,扫描成功。 我使用了来自GitHub的解决方案 我有0个错误,应用程序也“工作”,但当我把我的Visa卡添加到手机背面时,我什么也得不到 我的第一个问题是:哪个协议使用Visa卡?(发现标签、技术或NDEF)。我想这就是我的程序处于“空闲”状态的

这是第一次,我想为WinPhone和Android项目跨平台实现NFC到Xamarin.Forms

我在Android上测试我的应用程序,但什么都没发生。 作为一个工具,我使用了Visa Pay Wave卡,我在Android程序reTag中测试了该卡,扫描成功。 我使用了来自GitHub的解决方案 我有0个错误,应用程序也“工作”,但当我把我的Visa卡添加到手机背面时,我什么也得不到

我的第一个问题是:哪个协议使用Visa卡?(发现标签、技术或NDEF)。我想这就是我的程序处于“空闲”状态的原因

我的第二个问题是:你知道为什么我不能从程序中获取任何事件吗?(对于start,仅获取UID编号..)

以下是我的AndroidManifest.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
 android:installLocation="auto">
  <uses-sdk android:minSdkVersion="15" />
  <uses-permission android:name="android.permission.NFC" />
  <application android:label="NFCTest002.Android"></application>
  <uses-feature
    android:name="android.hardware.nfc"
    android:required="true" />
 <application>
 <activity
    android:name="MainActivity"
    android:label="@string/app_name" >
  <intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:mimeType="text/plain" />
  </intent-filter>
  <intent-filter>
    <action android:name="android.nfc.action.TECH_DISCOVERED"/>
  </intent-filter>
  <meta-data android:name="android.nfc.action.TECH_DISCOVERED"
      android:resource="@xml/nfc" />
  </activity>
 </application>
</manifest>

My MainActivity.cs:

using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Nfc;
using Android.OS;
using Poz1.NFCForms.Abstract;
using Poz1.NFCForms.Droid;
using System;

namespace NFCTest002.Droid
{
[Activity(Label = "NFCTest002", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new[] { NfcAdapter.ActionTechDiscovered })]
[MetaData(NfcAdapter.ActionTechDiscovered, Resource = "@xml/nfc")]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    public NfcAdapter NFCdevice;
    public NfcForms x;
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);

        NfcManager NfcManager = (NfcManager)Android.App.Application.Context.GetSystemService(Context.NfcService);
        NFCdevice = NfcManager.DefaultAdapter;

        Xamarin.Forms.DependencyService.Register<INfcForms, NfcForms>();
        x = Xamarin.Forms.DependencyService.Get<INfcForms>() as NfcForms;

        LoadApplication(new NFCTest002.App());
    }
    protected override void OnResume()
    {
        base.OnResume();
        if (NFCdevice != null)
        {
            var intent = new Intent(this, GetType()).AddFlags(ActivityFlags.SingleTop);
            NFCdevice.EnableForegroundDispatch
            (
                this,
                PendingIntent.GetActivity(this, 0, intent, 0),
                new[] { new IntentFilter(NfcAdapter.ActionTechDiscovered) },
                new String[][] {new string[] {
                        NFCTechs.Ndef,
                    },
                    new string[] {
                        NFCTechs.MifareClassic,
                    },
                }
            );
        }
    }

    protected override void OnPause()
    {
        base.OnPause();
        NFCdevice.DisableForegroundDispatch(this);
    }

    protected override void OnNewIntent(Intent intent)
    {
        base.OnNewIntent(intent);
        x.OnNewIntent(this, intent);
    }
}
}
使用Android.App;
使用Android.Content;
使用Android.Content.PM;
使用Android.Nfc;
使用Android.OS;
使用Poz1.NFCForms.Abstract;
使用Poz1.NFCForms.Droid;
使用制度;
名称空间NFCTest002.Droid
{
[活动(Label=“NFCTest002”,Icon=“@drawable/Icon”,Theme=“@style/MainTheme”,MainLauncher=true,ConfigurationChanges=ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(新[]{NfcAdapter.ActionTechDiscovered}]
[元数据(NfcAdapter.ActionTechDiscovered,Resource=“@xml/nfc”)]
公共类MainActivity:全局::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
公共NfcAdapter NFC设备;
公共NFCFX表格;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
全局::Xamarin.Forms.Forms.Init(这个,bundle);
NfcManager NfcManager=(NfcManager)Android.App.Application.Context.GetSystemService(Context.NfcService);
NFCdevice=NfcManager.DefaultAdapter;
Xamarin.Forms.DependencyService.Register();
x=Xamarin.Forms.DependencyService.Get()作为NfcForms;
LoadApplication(新的NFCTest002.App());
}
受保护的覆盖void OnResume()
{
base.OnResume();
如果(NFCdevice!=null)
{
var intent=new intent(this,GetType()).AddFlags(ActivityFlags.SingleTop);
NFCdevice.EnableForegroundDispatch
(
这
PendingEvent.GetActivity(this,0,intent,0),
新[]{new IntentFilter(NfcAdapter.ActionTechDiscovered)},
新字符串[][{新字符串[]{
NFCTechs.Ndef,
},
新字符串[]{
NFCTechs.MifareClassic,
},
}
);
}
}
受保护的覆盖void OnPause()
{
base.OnPause();
NFC设备。禁止地面调度(本);
}
受保护的覆盖无效Wintent(意图)
{
基恩温特(意图);
x、 OnNewIntent(本,意图);
}
}
}
我已经将nfc.xml文件添加到资源文件夹和xml文件夹中,如果需要,我会发布它


内容页与我提供的GitHub链接中的内容页相同。

Visa payWave卡基于EMV标准。就射频通信协议而言,这些卡使用ISO/IEC 7816-4而不是ISO-DEP(ISO/IEC 14443-4)

在Android上,您可以使用TECH_发现的意图过滤器和适当的过滤器XML文件来提取这些卡片。对于这些卡,XML文件需要如下所示:

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <tech-list>
        <tech>android.nfc.tech.IsoDep</tech>
    </tech-list>
</resources>

由于EMV卡不包含任何NDEF结构化数据,NDEFèU查找到的意图过滤器无法与EMV卡一起使用。

您是否尝试过使用标准NFC标记进行读写操作。这可能会缩小Visa卡使用的连接范围?还有一个网站,上面有一个Android上NFC代码的最新示例platform@AaronThompson谢谢,我会尝试Android平台,但我需要xamarin.forms。这应该标记为正确答案。我的回答有误导性,因为我知道op想要模拟卡片,对不起。
NFCdevice.EnableForegroundDispatch(
        this,
        PendingIntent.GetActivity(this, 0, intent, 0),
        new[] { new IntentFilter(NfcAdapter.ActionTechDiscovered) },
        new String[][] {
            new string[] {
                NFCTechs.IsoDep,
            },
        }
);