Android Open Source - AndroidNdefImplementation Main Activity






From Project

Back to project page AndroidNdefImplementation.

License

The source code is released under:

GNU General Public License

If you think the Android project AndroidNdefImplementation listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fr.oversimple.nfc.ndefReader;
// www  . jav  a 2 s . com
import fr.oversimple.nfc.urlReader.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity implements NfcNdefReaderListener{

   private TextView demoTextView;
   private NfcNdefReader nfcUrlReader;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    demoTextView = (TextView) findViewById(R.id.demoTextview);
    
        nfcUrlReader = new NfcNdefReader(this);
        
    if(!nfcUrlReader.isNfcAvailableOnDevice()) {
      Toast.makeText(this, "Nfc is not available on this device", Toast.LENGTH_SHORT).show();
    }
    
    if(!nfcUrlReader.isNfcActivated()) {
      Toast.makeText(this, "Nfc is not activated, please activate it", Toast.LENGTH_SHORT).show();
    }
    nfcUrlReader.setNfcUrlReaderListener(this);
    nfcUrlReader.handleIntent(getIntent());
  }
  
  @Override
  protected void onResume() {
    super.onResume();
    nfcUrlReader.setupForegroundDispatch(this);
  }
  
  @Override
  protected void onPause() {
    nfcUrlReader.stopForegroundDispatch(this);
    super.onPause();
  }
  
  @Override
  protected void onNewIntent(Intent intent) {
    nfcUrlReader.handleIntent(intent);
  }

  @Override
  public void ndefDataRead(String ndefData) {
    demoTextView.setText(ndefData);
  }
}




Java Source Code List

fr.oversimple.nfc.ndefReader.MainActivity.java
fr.oversimple.nfc.ndefReader.NfcNdefReaderListener.java
fr.oversimple.nfc.ndefReader.NfcNdefReader.java