@TargetApi(14)
 private void initNFC() {
   NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
   if (nfc != null) {
     nfc.setNdefPushMessageCallback(new NfcCallback(server), this);
   }
 }
  @Override
  public FREObject call(FREContext arg0, FREObject[] arg1) {

    Activity a = arg0.getActivity();
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(a);

    try {
      if (adapter == null) {
        return FREObject.newObject(false);
      }
    } catch (Exception e) {
    }
    NfcNdefManager.getInstance().adapter = NfcAdapter.getDefaultAdapter(a);
    NfcNdefManager.getInstance().pIntent =
        PendingIntent.getActivity(
            a, 0, new Intent(a, a.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    IntentFilter ndefFilter = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
      ndefFilter.addDataType("text/plain");
    } catch (MalformedMimeTypeException mmte) {
    }
    NfcNdefManager.getInstance().ndefFilters = new IntentFilter[] {ndefFilter};

    IntentFilter tagFilter = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    NfcNdefManager.getInstance().tagFilters = new IntentFilter[] {tagFilter};

    try {
      return FREObject.newObject(true);
    } catch (Exception e) {
    }
    return null;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getResources().getBoolean(R.bool.portrait_only)) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    setContentView(R.layout.activity_review_poll);
    setupActionBar();

    if (getResources().getBoolean(R.bool.display_bottom_bar) == false) {
      findViewById(R.id.layout_bottom_bar).setVisibility(View.GONE);
    }

    AndroidApplication.getInstance().setCurrentActivity(this);
    AndroidApplication.getInstance().getNetworkInterface().lockGroup();

    btnStartPollPeriod = (Button) findViewById(R.id.button_start_poll_period);
    btnStartPollPeriod.setOnClickListener(this);

    if (savedInstanceState != null) {
      poll = (Poll) savedInstanceState.getSerializable("poll");
      sender = savedInstanceState.getString("sender");
    }

    Poll intentPoll = (Poll) getIntent().getSerializableExtra("poll");
    if (intentPoll != null) {
      poll = intentPoll;
      sender = getIntent().getStringExtra("sender");
    }

    FragmentManager fm = getFragmentManager();
    fragment = new PollReviewFragment();
    Bundle bundle = new Bundle();
    bundle.putSerializable("poll", poll);
    bundle.putString("sender", sender);
    fragment.setArguments(bundle);

    fm.beginTransaction().replace(R.id.fragment_container, fragment, "review").commit();

    // Is NFC available on this device?
    nfcAvailable = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC);

    if (nfcAvailable) {

      nfcAdapter = NfcAdapter.getDefaultAdapter(this);

      if (nfcAdapter.isEnabled()) {

        // Setting up a pending intent that is invoked when an NFC tag
        // is tapped on the back
        pendingIntent =
            PendingIntent.getActivity(
                this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
      } else {
        nfcAvailable = false;
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    consumpties.add(new Consumptie(1, "Fanta"));
    consumpties.add(new Consumptie(1, "Cola"));
    consumpties.add(new Consumptie(1, "Sprite"));

    consumpties.add(new Consumptie(2, "Grolsch Bier"));

    consumpties.add(new Consumptie(3, "Witte Wijn"));
    consumpties.add(new Consumptie(3, "Rode Wijn"));
    consumpties.add(new Consumptie(3, "Speciaal Bier"));

    nfcAdapter = NfcAdapter.getDefaultAdapter(this);

    if (nfcAdapter != null && nfcAdapter.isEnabled()) {

    } else {
      finish();
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
    // getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    setContentView(R.layout.activity_main);

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    if (mNfcAdapter == null) {
      // Stop here, we definitely need NFC
      Toast.makeText(this, "This device doesn't support NFC.", Toast.LENGTH_LONG).show();
      finish();
      return;
    }

    if (!mNfcAdapter.isEnabled()) {
      Toast.makeText(this, "NFC is disabled.", Toast.LENGTH_LONG).show();
    }

    handleIntent(getIntent());
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    deviceNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (deviceNfcAdapter != null) {
      // Refer back to createNdefMessage to send
      deviceNfcAdapter.setNdefPushMessageCallback(this, this);

      // This will be called if message sent successfully
      deviceNfcAdapter.setOnNdefPushCompleteCallback(this, this);
    } else {
      Toast.makeText(this, "NFC not available on your device.", Toast.LENGTH_LONG).show();
    }

    addMessageInput = (EditText) findViewById(R.id.txtBoxAddMessage);
    messagesToSend = (TextView) findViewById(R.id.txtMessageToSend);
    receivedMessageOutput = (TextView) findViewById(R.id.txtMessagesReceived);
    Button addMessage = (Button) findViewById(R.id.buttonAddMessage);

    updateTextViews();

    if (getIntent().getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) {
      handleNfcIntent(getIntent());
    }
  }
  public static boolean powerNfc(boolean isOn, Context context) {
    boolean success = false;
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);

    if (nfcAdapter != null) {
      Class<?> NfcManagerClass;
      Method setNfcEnabled;

      try {
        NfcManagerClass = Class.forName(nfcAdapter.getClass().getName());
        setNfcEnabled = NfcManagerClass.getDeclaredMethod(isOn ? "enable" : "disable");
        setNfcEnabled.setAccessible(true);
        success = (Boolean) setNfcEnabled.invoke(nfcAdapter);
      } catch (ClassNotFoundException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      } catch (NoSuchMethodException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      } catch (IllegalArgumentException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      } catch (IllegalAccessException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      } catch (InvocationTargetException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      }
    }

    return success;
  }
  @Override
  protected void onResume() {
    AndroidApplication.getInstance().setCurrentActivity(this);
    LocalBroadcastManager.getInstance(NetworkConfigActivity.this)
        .registerReceiver(
            serviceStartedListener,
            new IntentFilter(BroadcastIntentTypes.networkConnectionSuccessful));

    active = true;
    rescanWifiTask =
        new AsyncTask<Object, Object, Object>() {

          @Override
          protected Object doInBackground(Object... arg0) {

            while (active) {
              SystemClock.sleep(5000);
              wifi.startScan();
            }
            return null;
          }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

    if (nfcAdapter != null && nfcAdapter.isEnabled()) {
      nfcAvailable = true;
    }

    // make sure that this activity is the first one which can handle the
    // NFC tags
    if (nfcAvailable) {
      nfcAdapter.enableForegroundDispatch(this, pendingIntent, Utility.getNFCIntentFilters(), null);
    }

    super.onResume();
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    // set the main.xml layout of 3 editable textfields and an update
    // button:
    setContentView(R.layout.nfc_beam);
    findViewById(R.id.write_tag).setOnClickListener(mTagWriter);
    mName = ((EditText) findViewById(R.id.computer_name));
    mRAM = ((EditText) findViewById(R.id.computer_ram));
    mProcessor = ((EditText) findViewById(R.id.computer_processor));

    // get an instance of the context's cached NfcAdapter
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    // if null is returned this demo cannot run. Use this check if the
    // "required" parameter of <uses-feature> in the manifest is not set
    if (mNfcAdapter == null) {
      Toast.makeText(this, "Your device does not support NFC. Cannot run demo.", Toast.LENGTH_LONG)
          .show();
      finish();
      return;
    }

    // check if NFC is enabled
    checkNfcEnabled();

    // Handle foreground NFC scanning in this activity by creating a
    // PendingIntent with FLAG_ACTIVITY_SINGLE_TOP flag so each new scan
    // is not added to the Back Stack
    mNfcPendingIntent =
        PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    // Create intent filter to handle NDEF NFC tags detected from inside our
    // application when in "read mode":
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
      ndefDetected.addDataType("application/root.gast.playground.nfc");
    } catch (MalformedMimeTypeException e) {
      throw new RuntimeException("Could not add MIME type.", e);
    }

    // Create intent filter to detect any NFC tag when attempting to write
    // to a tag in "write mode"
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);

    // create IntentFilter arrays:
    mWriteTagFilters = new IntentFilter[] {tagDetected};
    mReadTagFilters = new IntentFilter[] {ndefDetected, tagDetected};

    // register the callback
    // usage: setNdefPushMessageCallback( callback, activity,
    // optionalExtraActivities)
    mNfcAdapter.setNdefPushMessageCallback(this, this);
  }
 private void enableNFCAdapterSenses() {
   if (mAdapter != null) {
     if (!mAdapter.isEnabled()) {
       showWirelessSettingsDialog();
     }
     mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
     mAdapter.enableForegroundNdefPush(this, mNdefPushMessage);
   }
 }
 @Override
 protected void onPause() {
   super.onPause();
   // disabling foreground dispatch:
   NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
   if (nfcAdapter != null) {
     nfcAdapter.disableForegroundDispatch(this);
   }
 }
Exemple #12
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_nfmain);

    mInfoText = (TextView) findViewById(R.id.textView);
    // Check for available NFC Adapter
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null) {
      mInfoText = (TextView) findViewById(R.id.textView);
      mInfoText.setText("NFC is not available on this device.");
    } else {
      // Register callback to set NDEF message
      mNfcAdapter.setNdefPushMessageCallback(this, this);
      // Register callback to listen for message-sent success
      mNfcAdapter.setOnNdefPushCompleteCallback(this, this);
    }

    // start Facebook Login
    Session.openActiveSession(
        this,
        true,
        new Session.StatusCallback() {

          // callback when session changes state
          @Override
          public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {

              // make request to the /me API
              Request.executeMeRequestAsync(
                  session,
                  new Request.GraphUserCallback() {

                    // callback after Graph API response with user object
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                      if (user != null) {
                        Toast.makeText(
                                getApplicationContext(),
                                "Welcome " + user.getName() + " : " + user.getId() + "!",
                                Toast.LENGTH_LONG)
                            .show();
                        userId = user.getId();
                      }
                    }
                  });
            }
          }
        });
  }
 public void checkNfcAvailibility() {
   nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
   if (nfcAdapter == null) {
     callbackContext.error(STATUS_NO_NFC);
   } else if (!nfcAdapter.isEnabled()) {
     callbackContext.error(STATUS_NFC_DISABLED);
   } else {
     callbackContext.success(STATUS_NFC_OK);
   }
 }
 /**
  * Check if the NFCAdapter is enable
  *
  * @return true if the NFCAdapter is available enable
  */
 public static boolean isNfcEnable(final Context pContext) {
   boolean ret = true;
   try {
     NfcAdapter adpater = NfcAdapter.getDefaultAdapter(pContext);
     ret = adpater != null && adpater.isEnabled();
   } catch (UnsupportedOperationException e) {
     ret = false;
   }
   return ret;
 }
  /** NFC書き込み可能状態にする */
  private void enableTagWriteMode() {

    // このアプリ以外がNFCに反応しないようにする
    mWriteTagFilters = new IntentFilter[] {new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED)};
    Intent intent = new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent nfcIntent = PendingIntent.getActivity(this, 0, intent, 0);

    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    nfcAdapter.enableForegroundDispatch(this, nfcIntent, mWriteTagFilters, null);
  }
Exemple #16
0
 @Override
 protected void onResume() {
   super.onResume();
   if (mAdapter != null) {
     if (!mAdapter.isEnabled()) {
       showWirelessSettingsDialog();
     }
     mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
   }
 };
  public static boolean checkNfcPowerStatus(Context context) {
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
    boolean enabled = false;

    if (nfcAdapter != null) {
      enabled = nfcAdapter.isEnabled();
    }

    return enabled;
  }
Exemple #18
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null || !mNfcAdapter.isEnabled()) {
      Toast.makeText(this, "NFC is turn off or disabled", Toast.LENGTH_LONG).show();
    }

    handleIntend(getIntent());
  }
Exemple #19
0
  private void enableTagWriteMode() {
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    IntentFilter[] mWriteTagFilters = new IntentFilter[] {tagDetected};
    PendingIntent pendingIntent =
        PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE);
    NfcAdapter adapter = manager.getDefaultAdapter();
    adapter.enableForegroundDispatch(this, pendingIntent, mWriteTagFilters, null);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pass_bolt_login);

    resolveIntent(getIntent());

    // Set up the login form.
    mUserNameView = (AutoCompleteTextView) findViewById(R.id.username);
    // populateAutoComplete();

    mPasswordView = (EditText) findViewById(R.id.password);

    emailLoginFormLayout = (LinearLayout) findViewById(R.id.email_login_form);

    mCardIDView = (EditText) findViewById(R.id.card_id);
    mCardIDView.setKeyListener(null);

    Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
    mEmailSignInButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            attemptLogin(view);
          }
        });

    mLoginFormView = findViewById(R.id.login_form);
    mProgressView = findViewById(R.id.login_progress);

    mDialog = new AlertDialog.Builder(this).setNeutralButton("Ok", null).create();

    mAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mAdapter == null) {
      showMessage(R.string.error, R.string.no_nfc);
      finish();
      return;
    }

    if (!mAdapter.isEnabled()) {
      showMessage(R.string.error, R.string.disabled_nfc);
      finish();
      return;
    }

    mPendingIntent =
        PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    mNdefPushMessage =
        new NdefMessage(
            new NdefRecord[] {
              createNewTextRecord("Message from NFC Reader", Locale.ENGLISH, true)
            });
  }
  @SuppressLint({"NewApi"})
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_write_uri);
    // getActionBar().setDisplayHomeAsUpEnabled(true);

    ctx = this;
    Button btnWrite = (Button) findViewById(R.id.button);
    final TextView message = (TextView) findViewById(R.id.edit_message);

    btnWrite.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            try {
              if (mytag == null) {
                Toast.makeText(ctx, ctx.getString(R.string.error_detected), Toast.LENGTH_LONG)
                    .show();
              } else {
                // Write TNF_WELL_KNOWN with uri
                write(message.getText().toString(), mytag);
                // Write customize mime with content
                // write(message.getText().toString(),mytag);
                Toast.makeText(ctx, ctx.getString(R.string.ok_writing), Toast.LENGTH_LONG).show();
              }
            } catch (IOException e) {
              Toast.makeText(ctx, ctx.getString(R.string.error_writing), Toast.LENGTH_LONG).show();
              e.printStackTrace();
            } catch (FormatException e) {
              Toast.makeText(ctx, ctx.getString(R.string.error_writing), Toast.LENGTH_LONG).show();
              e.printStackTrace();
            }
          }
        });

    adapter = NfcAdapter.getDefaultAdapter(this);
    if (adapter == null) {
      // NFC is not available
      finish();
      return;
    }
    if (!adapter.isEnabled()) {
      // NFC is disabled
      finish();
      return;
    }
    pendingIntent =
        PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    tagDetected.addCategory(Intent.CATEGORY_DEFAULT);
    writeTagFilters = new IntentFilter[] {tagDetected};
  }
 public void startReadingNfcV() {
   nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
   if (nfcAdapter == null) {
     callbackContext.error(STATUS_NO_NFC);
   } else if (!nfcAdapter.isEnabled()) {
     callbackContext.error(STATUS_NFC_DISABLED);
   } else {
     this.isReading = true;
     this.isWriting = false;
     setupForegroundDispatch(getActivity(), nfcAdapter);
   }
 }
 // Check whether NFC is enabled on the device on not
 public static boolean isNFCEnabled(Context appContext) {
   NfcManager manager = (NfcManager) appContext.getSystemService(Context.NFC_SERVICE);
   NfcAdapter adapter = manager.getDefaultAdapter();
   if (adapter != null && adapter.isEnabled()) {
     Log.i(TAG, "NFC Supproted and Enabled");
     return true;
   } else if (adapter != null && !adapter.isEnabled()) {
     Log.i(TAG, "NFC Supproted and Disabled");
     return false;
   }
   return false;
 }
  private void initNFC() {
    nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (nfcAdapter == null) {
      Toast.makeText(this, getString(R.string.nfc_feature_not_supported_txt), Toast.LENGTH_LONG)
          .show();
      finish();
      return;
    }
    if (!nfcAdapter.isEnabled()) {
      Toast.makeText(this, getString(R.string.nfc_disabled_txt), Toast.LENGTH_LONG).show();
    } else {

    }
  }
 @Override
 protected void onResume() {
   // TODO Auto-generated method stub
   super.onResume();
   if (NFCAdapter != null)
     NFCAdapter.enableForegroundDispatch(this, pendingIntent, i, techListsArray);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // creating pending intent
    pendingIntent =
        PendingIntent.getActivity(
            this,
            0,
            new Intent(getApplicationContext(), this.getClass())
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY),
            0);

    i[0] = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    // creating tech list for tag
    techListsArray =
        new String[][] {
          new String[] {
            NfcV.class.getName(),
            NfcA.class.getName(),
            NfcB.class.getName(),
            NfcF.class.getName(),
            Ndef.class.getName(),
            NdefFormatable.class.getName(),
            MifareClassic.class.getName(),
            MifareUltralight.class.getName()
          }
        };

    // creating object of nfc adapter of mobile device
    NFCAdapter = NfcAdapter.getDefaultAdapter(this);

    // if app is opened after pop up....
    ScanTag(getIntent());
  }
 @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
 void initNfcTransfer(PeerNetInfo qrData) {
   if (mNfcAdapter != null && mNfcAdapter.isEnabled() && useNFC) {
     NdefMessage msg =
         new NdefMessage(
             new NdefRecord[] {
               new NdefRecord(
                   NdefRecord.TNF_MIME_MEDIA,
                   "application/com.xconns.peerdevicenet.connector"
                       .getBytes(Charset.forName("US-ASCII")),
                   new byte[0],
                   qrData.encode().getBytes(Charset.forName("US-ASCII")))
             });
     mNfcAdapter.setNdefPushMessage(msg, this);
   }
 }
 public void testNfcFeatures() {
   if (NfcAdapter.getDefaultAdapter(mContext) != null) {
     assertAvailable(PackageManager.FEATURE_NFC);
   } else {
     assertNotAvailable(PackageManager.FEATURE_NFC);
   }
 }
 @Override
 protected void onNewIntent(Intent intent) {
   super.onNewIntent(intent);
   if (nfcAdapter != null && nfcAdapter.isEnabled()) {
     nfcAsyncTask = new NfcAsyncTask(intent);
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });

    nfcAdapter = NfcAdapter.getDefaultAdapter(this); // argument is "Context"
    if (nfcAdapter == null) {
      Toast.makeText(this, "Not a NFC device", Toast.LENGTH_SHORT).show();
      return;
    }

    // TODO go AsyncTask
    onNewIntent(getIntent());
  }