Ejemplo n.º 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);
  }
Ejemplo n.º 2
0
  @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();
  }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 6
0
 /** 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);
   }
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
  }
Ejemplo n.º 11
0
 @Override
 protected void onResume() {
   super.onResume();
   if (mAdapter != null) {
     if (!mAdapter.isEnabled()) {
       showWirelessSettingsDialog();
     }
     mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
   }
 };
Ejemplo n.º 12
0
  /** 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);
  }
Ejemplo n.º 13
0
  @Override
  protected void onResume() {
    super.onResume();

    initNfc();
    checkBT();

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

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

    refreshStatus();
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 18
0
 @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;
     }
   }
 }
Ejemplo n.º 19
0
 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();
 }
Ejemplo n.º 20
0
  @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);
    }
  }
Ejemplo n.º 22
0
  /**
   * @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);
  }
Ejemplo n.º 23
0
  /* 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);
  }
Ejemplo n.º 24
0
 @Override
 public void onResume() {
   super.onResume();
   mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
 }
Ejemplo n.º 25
0
 /**
  * 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);
 }
Ejemplo n.º 27
0
 private void enableTagReadMode() {
   mWriteMode = false;
   mNfcAdapter.enableForegroundDispatch(this, mNfcPendingIntent, mReadTagFilters, null);
 }
 @Override
 protected void onResume() {
   super.onResume();
   nfcAdapter.enableForegroundDispatch(this, pendingIntent, null, null);
 }
Ejemplo n.º 29
0
 @Override
 public void onResume() {
   super.onResume();
   nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFiltersArray, techListsArray);
 }
Ejemplo n.º 30
0
 public void onResume() {
   super.onResume();
   initContent();
   mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
 }