title: How to set mobile as NFC tag with host-based card emulation (HCE)
body: <p>I want to write a program that can store a unique ID and then send it as NFC tag to another NFC reader devices. How can I send my code (<code>nfcTag</code>) to the NFC reader? Can I do this without having an AID for my application?</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          PackageManager pm = this.getPackageManager();
          String nfcTag="123456789";                          //the code wants to work as NFC tag
          TextView msg = (TextView) findViewById(R.id.txtShow);
          byte[] t2 = new byte[9];                            //t2 return from processCommandApdu
  
          t2 = nfcTag.getBytes();
  
          @Override
          public byte[] processCommandApdu(byte[] apdu, Bundle extras) {
              msg.setText(nfcTag);
  
  
  
              return t2;                  //return nfcTag too read with NFC tag reader devices
          }
          @Override
          public void onDeactivated(int reason) {
              msg.setText("Your phone does not has HCE hardware.");
  
              if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
                  // HCE is not available on the device.
                  Toast.makeText(this, "The device does not has HCE hardware.",
                          Toast.LENGTH_SHORT).show();
              }
              else {
                  Toast.makeText(this, "HCE supported on your device.",
                          Toast.LENGTH_SHORT).show();
              }
          }
      }
  }
  </code></pre>
  
  <p>and here is AndroidManifest.xml</p>
  
  <pre><code>    &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;service android:name=".MyHostApduService" android:exported="true"
              android:permission="android.permission.BIND_NFC_SERVICE"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/&gt;
              &lt;/intent-filter&gt;
          &lt;/service&gt;
  
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>