Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.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设备之间的仿真_Android_Nfc - Fatal编程技术网

如何在android中启动两个nfc设备之间的仿真

如何在android中启动两个nfc设备之间的仿真,android,nfc,Android,Nfc,我必须将标签从一个设备共享到另一个设备,我有android 2.3.3 galaxy。 请与我分享一些代码,用于将标签从一个设备共享到另一个设备 我从开发者网站上获取了这段代码,但在这行代码中显示了错误 mNfcAdapter.setNdefPushMessageCallback(this, this); // Check for available NFC Adapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this); if (

我必须将标签从一个设备共享到另一个设备,我有android 2.3.3 galaxy。 请与我分享一些代码,用于将标签从一个设备共享到另一个设备

我从开发者网站上获取了这段代码,但在这行代码中显示了错误

 mNfcAdapter.setNdefPushMessageCallback(this, this);


  // Check for available NFC Adapter
 mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
 if (mNfcAdapter == null) {
     Toast.makeText(this, "NFC is not available", Toast.LENGTH_LONG).show();
     finish();
     return;
 }
 // Register callback
 mNfcAdapter.setNdefPushMessageCallback(this, this);
现在我使用的是enable forground消息,但它工作得很好,但如何查看仿真

public class DemoNFCtagActivity extends Activity {

    NdefMessage msg;

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();

           mNfcAdapter.enableForegroundNdefPush(this,msg );

    }

    NfcAdapter mNfcAdapter;
    TextView textView;

    Button btnEmulation;
    PendingIntent mNfcPendingIntent;
    IntentFilter[] mNdefExchangeFilters;
    NdefMessage message;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

       // TextView textView = (TextView) findViewById(R.id.textView);
        // Check for available NFC Adapter
        mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (mNfcAdapter == null) {
            Toast.makeText(this, "NFC is not available", Toast.LENGTH_LONG).show();
            finish();
            return;
        }
        // Register callback
    //    mNfcAdapter.setNdefPushMessageCallback(this, this);


        String text = ("Beam me up, Android!\n\n" +
                "Beam Time: " + System.currentTimeMillis());
         msg = new NdefMessage(
                new NdefRecord[] { createMimeRecord(
                        "application/com.example.android.beam", text.getBytes())
         /**
          * The Android Application Record (AAR) is commented out. When a device
          * receives a push with an AAR in it, the application specified in the AAR
          * is guaranteed to run. The AAR overrides the tag dispatch system.
          * You can add it back in to guarantee that this
          * activity starts when receiving a beamed message. For now, this code
          * uses the tag dispatch system.
          */
          //,NdefRecord.createApplicationRecord("com.example.android.beam")
        });     
    }

    public NdefRecord createMimeRecord(String mimeType, byte[] payload) {
        byte[] mimeBytes = mimeType.getBytes(Charset.forName("US-ASCII"));
        NdefRecord mimeRecord = new NdefRecord(
                NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload);
        return mimeRecord;
    }
}

NfcAdapter.setNdefPushMessageCallback()
仅在Android 4.0及更高版本中可用。请改用
enableforegroundendefpush()

我有另一个问题,我正在使用上面描述的代码。。但是如何看到仿真意味着代码没有显示任何错误,但什么也没有发生。请帮助