Example #1
1
  /**
   * here is where we define & enable foreground dispatch of 'ndef_discovered' intents to this
   * activity notice: this must be called while activity is in foreground!
   *
   * @param activity
   * @param adapter
   */
  private void setupForegroundDispatch(Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    final PendingIntent pendingIntent =
        PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
    IntentFilter[] filters = new IntentFilter[2];
    String[][] techList = new String[][] {};

    // detect ndef messages
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);

    // detect other types of nfc tags
    filters[1] = new IntentFilter();
    filters[1].addAction(NfcAdapter.ACTION_TAG_DISCOVERED);

    try {
      filters[0].addDataType(MIME_TEXT_PLAIN);
    } catch (IntentFilter.MalformedMimeTypeException e) {
      Log.d(TAG, "bad mime type", e);
      shutdown();
    }

    // enable foreground dispatch to this activity
    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
  }
  @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();
  }
Example #3
0
 @Override
 public void onResume() {
   super.onResume();
   if (mNfcAdapter != null)
     mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, mIntentFilters, null);
   Log.d("onResume", "onResume");
 }
 @Override
 protected void onResume() {
   // TODO Auto-generated method stub
   super.onResume();
   if (NFCAdapter != null)
     NFCAdapter.enableForegroundDispatch(this, pendingIntent, i, techListsArray);
 }
Example #5
0
 @Override
 protected void onResume() {
   super.onResume();
   nfcAdapter.enableForegroundDispatch(this, mNfcPendingIntent, mMifareFilters, mTechLists);
   receiveTab.append("\nAdded new mifare intent filter");
   Intent intent = getIntent();
   resolveIntent(intent);
 }
 /** Starts writing to any writable NFC tag nearby. */
 private void enableTagWriteMode() {
   IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
   IntentFilter[] writeTagFilters = new IntentFilter[] {tagDetected};
   PendingIntent nfcPendingIntent =
       PendingIntent.getActivity(
           this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
   nfcAdapter.enableForegroundDispatch(this, nfcPendingIntent, writeTagFilters, null);
 }
 private void enableNFCAdapterSenses() {
   if (mAdapter != null) {
     if (!mAdapter.isEnabled()) {
       showWirelessSettingsDialog();
     }
     mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
     mAdapter.enableForegroundNdefPush(this, mNdefPushMessage);
   }
 }
Example #8
0
  private void enableForegroundDispatchSystem() {
    Intent intent = new Intent(this, NFCActivity.class);
    intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);

    PendingIntent mPendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    IntentFilter[] mIntentFilter = new IntentFilter[] {};

    mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, mIntentFilter, null);
  }
 /* Le code pour NFC */
 @Override
 protected void onResume() {
   super.onResume();
   Intent intent = new Intent(this, this.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
   PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
   IntentFilter[] filters = null;
   String[][] techLists = null;
   nfcAdapter.enableForegroundDispatch(this, pendingIntent, filters, techLists);
 }
Example #10
0
  @SuppressLint("NewApi")
  public void enableForegroundMode() {
    Log.d("TAG", "enableForegroundMode");

    IntentFilter tagDetected =
        new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); // filter for all
    IntentFilter[] writeTagFilters = new IntentFilter[] {tagDetected};
    nfcAdapter.enableForegroundDispatch(this, nfcPendingIntent, writeTagFilters, null);
  }
Example #11
0
 @Override
 protected void onResume() {
   super.onResume();
   if (mAdapter != null) {
     if (!mAdapter.isEnabled()) {
       showWirelessSettingsDialog();
     }
     mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
   }
 };
  /** 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);
  }
Example #13
0
  @Override
  protected void onResume() {
    super.onResume();

    initNfc();
    checkBT();

    if (mNfcAdapter != null)
      mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, mIntentFilters, mNFCTechLists);
  }
Example #14
0
  @Override
  protected void onResume() {
    super.onResume();

    if (nfcAdapter != null)
      nfcAdapter.enableForegroundDispatch(
          this, pendingIntent, CardManager.FILTERS, CardManager.TECHLISTS);

    refreshStatus();
  }
Example #15
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);
  }
Example #16
0
  @Override
  protected void onResume() {

    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    IntentFilter[] intentFilter = new IntentFilter[] {};

    nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFilter, null);

    super.onResume();
  }
  public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    final PendingIntent pendingIntent =
        PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);

    IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
    String[][] techList = new String[][] {new String[] {NfcV.class.getName()}};
    try {
      filter.addDataType("*/*");
    } catch (IntentFilter.MalformedMimeTypeException e) {
      throw new RuntimeException("ERROR", e);
    }
    IntentFilter[] filters = new IntentFilter[] {filter};
    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
  }
 @Override
 public void onResume() {
   super.onResume();
   nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFilters, techList);
   if (isnews) {
     if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(getIntent().getAction())) {
       if (userAccount != null) {
         String tmp = BaseNfc.ScanNfc(this, getIntent());
         if (tmp != null) {
           userAccount.setText(tmp);
           Logining();
         }
       }
       intents = getIntent();
       isnews = false;
     }
   }
 }
 public void onResume() {
   try {
     if (nfcAdapter != null) {
       nfcAdapter.enableForegroundDispatch(this, pendingIntent, filters, techLists);
     } else {
       throw new FsgException(
           new NullPointerException(
               "'Der NfcAdapter ist ein \"null\"-Objekt. Grund: Keine NFC-Unterstützung auf dem Gerät"),
           this.getClass().toString(),
           FsgException.NOT_NFC_SUPPORT);
     }
   } catch (FsgException e1) {
     Intent mIntent = new Intent(this, ErrorActivity.class);
     mIntent.putExtra("Exception", e1);
     startActivity(mIntent);
     finish();
   }
   super.onResume();
 }
  @Override
  protected void onResume() {
    AndroidApplication.getInstance().setCurrentActivity(this);
    LocalBroadcastManager.getInstance(this)
        .registerReceiver(
            showNextActivityListener, new IntentFilter(BroadcastIntentTypes.showNextActivity));

    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();
  }
  @Override
  protected void onResume() {

    super.onResume();

    // creating pending intent:
    PendingIntent pendingIntent =
        PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    // creating intent receiver for NFC events:
    IntentFilter filter = new IntentFilter();
    filter.addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
    filter.addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filter.addAction(NfcAdapter.ACTION_TECH_DISCOVERED);
    // enabling foreground dispatch for getting intent from NFC event:
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (nfcAdapter != null) {
      nfcAdapter.enableForegroundDispatch(
          this, pendingIntent, new IntentFilter[] {filter}, this.NTC_TECH_LIST);
    }
  }
  /**
   * @param activity The corresponding {@link Activity} requesting the foreground dispatch.
   * @param adapter The {@link NfcAdapter} used for the foreground dispatch.
   */
  public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    final PendingIntent pendingIntent =
        PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][] {};

    // Notice that this is the same filter as in our manifest.
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
      filters[0].addDataType(MIME_TEXT_PLAIN);
    } catch (MalformedMimeTypeException e) {
      throw new RuntimeException("Check your mime type.");
    }

    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
  }
  /* Called when the activity will start interacting with the user. */
  @Override
  protected void onResume() {
    super.onResume();

    // Double check if NFC is enabled
    checkNfcEnabled();

    Log.d(TAG, "onResume: " + getIntent());

    if (getIntent().getAction() != null) {
      // tag received when app is not running and not in the foreground:
      if (getIntent().getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) {
        NdefMessage[] msgs = getNdefMessagesFromIntent(getIntent());
        NdefRecord record = msgs[0].getRecords()[0];
        byte[] payload = record.getPayload();
        setTextFieldValues(new String(payload));
      }
    }

    // Enable priority for current activity to detect scanned tags
    // enableForegroundDispatch( activity, pendingIntent,
    // intentsFiltersArray, techListsArray );
    mNfcAdapter.enableForegroundDispatch(this, mNfcPendingIntent, mReadTagFilters, null);
  }
Example #24
0
 @Override
 public void onResume() {
   super.onResume();
   mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
 }
 /**
  * Activate NFC dispacher to read NFC Card Set the most important priority to the foreground
  * application
  */
 public void enableDispatch() {
   if (mNfcAdapter != null) {
     mNfcAdapter.enableForegroundDispatch(mActivity, mPendingIntent, INTENT_FILTER, TECH_LIST);
   }
 }
 private void WriteModeOn() {
   writeMode = true;
   adapter.enableForegroundDispatch(this, pendingIntent, writeTagFilters, null);
 }
 private void enableTagReadMode() {
   mWriteMode = false;
   mNfcAdapter.enableForegroundDispatch(this, mNfcPendingIntent, mReadTagFilters, null);
 }
 @Override
 protected void onResume() {
   super.onResume();
   nfcAdapter.enableForegroundDispatch(this, pendingIntent, null, null);
 }
Example #29
0
 @Override
 public void onResume() {
   super.onResume();
   nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFiltersArray, techListsArray);
 }
Example #30
0
 public void onResume() {
   super.onResume();
   initContent();
   mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
 }