我需要NFC和
Android的帮助.
在进行了大量研究以在Android上模拟Mifare 4K后,我发现存在的唯一补丁是针对2.3.4.在StackOverFlow中,NFCGuy告诉我们,自Android的API 14以来,它不是ROM的必要补丁,因此我们可以使用隐藏的Nfc_extras包打开卡仿真.
我使用带反射的NFC_EXTRAS编译了一个APK,并将我的签名和包添加到了nfcee_access.xml.
在我将cardEmulationRoute设置为ON_WHEN_SCREEN_ON之后,我在logcat中得到一个输出,告诉我NFCEE为ON且NFC_CC为ON,但是当我让我的Nexus S接近ACR122时,它没有检测到2.3.4补丁制造商可能的仿真Mifare 4K得到.我可以得到一张无法识别的智能卡(我想这是SE就像一张智能卡),但我需要使用模拟的Mifare.
我是否需要修改lib-nfc,因为它在2.3.4补丁中被修改以使该applet正常工作(Mifare Manager)?或者我的应用程序访问该包应该是什么?
我正在下载android源码以将2.3.4补丁移植到4.1,但是看看他们发布的差异,lib-nfc库上只有4.1的区别. (定义评论,理论上用于卡片仿真)
也许没有必要重新编译一个修改过的ROM,我错过了一小步来获得模拟的Mifare 4k.
感谢StackOverFlow中所有人的帮助
问候
private void getSecureElement(){ try{ //Obtenemos la clase NFCAdapterExtras Class nfcExtrasClazz = Class.forName("com.android.nfc_extras.NfcAdapterExtras"); if (nfcExtrasClazz == null){ Log.w("EnableCardEmu","No existe la clase Extras"); return; } Log.w("EnableCardEmu","Existe la clase"); //Obtenemos el método "get" de dicha clase Method getMethod = nfcExtrasClazz.getMethod("get",Class.forName("android.nfc.NfcAdapter")); if (getMethod == null) { Log.w("EnableCardEmu","No existe el método"); } else { Log.w("EnableCardEmu","Existe el método"); //Obtenemos el manager del componente NFC del dispositivo NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); if (adapter == null) Log.w("EnableCardEmu","Adapter es null"); else { //Instancia del SecureElement Log.w("EnableCardEmu","Adapter NO es null"); nfcExtras = getMethod.invoke(null,adapter); Method getEEMethod = nfcExtras.getClass().getMethod("getEmbeddedExecutionEnvironment",(Class[]) null); embebbed = getEEMethod.invoke(nfcExtras,(Object[]) null); } } } catch (InvocationTargetException ee){ Log.w("EnableCardEmu",ee.getTargetException()); } catch (Exception e){ Log.w("EnableCardEmu",e.getClass().getName() + " / " + e.getMessage()); StackTraceElement[] a = e.getStackTrace(); for (StackTraceElement aa : a){ Log.w("EnableCardEmu",aa.toString()); } } } private void deactivateCardEmulation(){ try{ Class clss = Class.forName("com.android.nfc_extras.NfcAdapterExtras"); Class[] cs = clss.getDeclaredClasses(); /* for (Class cc : cs){ Log.w("EnableCardEmu",cc.getName();) }*/ //Class route = Class.forName("com.android.nfc_extras.NfcAdapterExtras$CardEmulationRoute"); Constructor c = cs[0].getConstructor(Integer.TYPE,Class.forName("com.android.nfc_extras.NfcExecutionEnvironment")); Object routeOn = c.newInstance(1,null); Class cls = nfcExtras.getClass(); Method mtd = cls.getMethod("setCardEmulationRoute",cs[0]); mtd.invoke(nfcExtras,routeOn); } catch (InvocationTargetException ee){ Log.w("EnableCardEmu",ee.getTargetException()); } catch (Exception e){ Log.w("EnableCardEmu",e.getClass().getName() + " / " + e.getMessage()); } } private void activateCardEmulation(){ try{ Class clss = Class.forName("com.android.nfc_extras.NfcAdapterExtras"); Class[] cs = clss.getDeclaredClasses(); /* for (Class cc : cs){ Log.w("EnableCardEmu",Class.forName("com.android.nfc_extras.NfcExecutionEnvironment")); Object routeOn = c.newInstance(2,embebbed); Class cls = nfcExtras.getClass(); Method mtd = cls.getMethod("setCardEmulationRoute",e.getClass().getName() + " / " + e.getMessage()); } }
解决方法
我认为问题可能出在Object routeOn = c.newInstance(2,embebbed)中.看起来这个对象是错误的类型(我不是阅读反射代码的专家).
这就是我如何做到这一点,没有反射,它工作正常(ISO 14443-4A卡和MIFARE Classic卡同时由设备模拟):
Context mContext; // initialize this NfcAdapterExtras mAdapterExtras = NfcAdapterExtras.get(NfcAdapter.getDefaultAdapter(mContext)); NfcExecutionEnvironment mEe = mAdapterExtras.getEmbeddedExecutionEnvironment(); mAdapterExtras.setCardEmulationRoute( new CardEmulationRoute(CardEmulationRoute.ROUTE_ON_WHEN_SCREEN_ON,mEe));
无需为此修改libnfc-nxp.