与Delphi中的Mifare DESFire通信

时间:2014-11-05 21:55:23

标签: android nfc delphi-xe firemonkey mifare

我想在Delphi中编写应用程序,它可以与Android手机和DESFire卡通信。我知道,我必须向卡片和卡片发送一些字节来回答我。我读过有关它的文章:

https://ridrix.wordpress.com/2009/09/19/mifare-desfire-communication-example/

我不知道,如何从卡中写入和读取字节?我根据Daniel Magin编写了简单的应用程序:

http://www.danielmagin.de/blog/index.php/2014/09/nfc-android-application-with-delphi-xe6-and-xe7/

此程序只能从卡读取UID。

function TNfc.ReadNFCUID: string;
var
  Intent: JIntent;
  jIntentName: JString;
  IntentName: string;
  tagId: Androidapi.JNIBridge.TJavaArray<Byte>;
  tagFromIntent: JParcelable;
  id: string;
  i: Integer;

begin
  id := '';
  Intent := SharedActivity.getIntent;

  if Intent <> nil then
  begin
    jIntentName := Intent.getAction;
    IntentName := JStringToString(jIntentName);

    tagId := Intent.getByteArrayExtra(TJNFCAdapter.JavaClass.EXTRA_ID);

    tagFromIntent := Intent.getParcelableExtra
      (TJNFCAdapter.JavaClass.EXTRA_TAG);
    if (tagId <> nil) and (tagFromIntent <> nil) then
    begin
      for i := 0 to tagId.Length - 1 do
        id := id + IntToHex(tagId.Items[i], 2);
    end;
  end;

  Result := id;

end;

1 个答案:

答案 0 :(得分:1)

我找到了问题的解决方案:

..
var
    isoNFC : JIsoDep;
    tag : JTag;
    aRawData : TJavaByteArray;
    aResponse : TJavaByteArray;

begin
  aRawData := TJavaByteArray.Create(1);

  tag := TJTag.Wrap((CurrentNFCTag as ILocalObject).GetObjectID);
  isoNFC := TJIsoDep.JavaClass.get(tag);
  isoNFC.connect();

  aRawData.Items[0] := TCmd.GetApplicationIDs;
  aResponse := isoNFC.transceive(aRawData);
..