Example usage for android.nfc NfcAdapter FLAG_READER_NO_PLATFORM_SOUNDS

List of usage examples for android.nfc NfcAdapter FLAG_READER_NO_PLATFORM_SOUNDS

Introduction

In this page you can find the example usage for android.nfc NfcAdapter FLAG_READER_NO_PLATFORM_SOUNDS.

Prototype

int FLAG_READER_NO_PLATFORM_SOUNDS

To view the source code for android.nfc NfcAdapter FLAG_READER_NO_PLATFORM_SOUNDS.

Click Source Link

Document

Flag for use with #enableReaderMode(Activity,ReaderCallback,int,Bundle) .

Usage

From source file:com.idevity.card.read.ReadMain.java

/**
 * Method onCreate.//from w  w  w . java2  s.  c  o  m
 * 
 * @param savedInstanceState
 *            Bundle
 */
@TargetApi(19)
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_read_main);

    /*
     * We will take over the NFC Interface while in the foreground so there
     * is no additional read attempt.
     * 
     * If on KitKat, we will set a filter and ignore any callbacks.
     */
    /****************** Initialize NFC ******************/
    if (debug) {
        Log.d(TAG, "Getting Adaptor...");
    }
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
    /*
     * Platform version specific handling: KitKat
     */
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (debug) {
            Log.d(TAG, "Setting Adaptor up for KitKat");
        }
        ReaderCallback listener = new ReaderCallback() {
            public void onTagDiscovered(Tag tag) {
                /*
                 * Discard the tags here
                 */
                tag = null;
            }
        };
        int flags = NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK
                | NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS;
        adapter.enableReaderMode(this, listener, flags, null);
    }

    // Get preferences / settings that have been saved
    // get the show log

    this.sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    boolean showLog = this.sharedPref.getBoolean(g.getShowLog(), false);

    // Create the adapter that will return a fragment for each of the three
    // primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager(), this.sharedPref);

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is
    // no hierarchical
    // parent.
    actionBar.setHomeButtonEnabled(true);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener
    // for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select
            // the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if
            // we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    /*
     * Use the following to determine content to show in the tabs. First,
     * check to see if there is an active intent Also, check to see if there
     * is an active saved instance state If, active intent - use active
     * intent; if active intent = null, and saved instance state !null, use
     * saved instance state; else return user to "main" instructions
     */
    boolean hasIntent = false;
    boolean hasSavedData = false;

    try {
        if (getIntent().getExtras().getByteArray(g.getCardData()) != null) {
            hasIntent = true;
        }
    } catch (Throwable e) {
        Log.e(TAG, "Error: intent " + e.getMessage());
    }

    try {
        if (g.getCard() != null) {
            hasSavedData = true;
        }
    } catch (Throwable e) {
        Log.e(TAG, "Error: saved instance state " + e.getMessage());
    }

    // if intent, populate the variables with the intent values
    // else if saved instance, populate the same variables with the saved
    // instance state
    // else return user to read800-73 activity to read a new card

    if (hasIntent) {
        logStringBuffer = getIntent().getExtras().getString(g.getReaderLog());
        byte[] _data = getIntent().getExtras().getByteArray(g.getCardData());
        this.carddata = new CardData80073(_data);
        if (debug) {
            Log.d(TAG, "Using new card data");
        }
        g.putCard(carddata.toByteArray());
        g.putLogData(logStringBuffer);

    } else if (hasSavedData) {
        logStringBuffer = g.getLogData();
        byte[] _data = g.getCard();
        this.carddata = new CardData80073(_data);
        Log.e(TAG, "Using saved card data");
    } else {
        Intent returnuser = new Intent(this, Read80073.class);
        startActivity(returnuser);
        Log.e(TAG, "No card data found; returning user to read a new card.");
    }

    /*
     * For each of the sections in the app, add a tab to the action bar.
     */
    Tab tabA = actionBar.newTab();
    tabA.setText(getString(R.string.TabRead_Title));
    tabA.setTabListener(this);
    actionBar.addTab(tabA);

    // this one will become the CAK tab
    Tab tabB = actionBar.newTab();
    tabB.setText(getString(R.string.TabCert_Title));
    tabB.setTabListener(this);
    actionBar.addTab(tabB);

    // this one will become the CHUID tab
    Tab tabC = actionBar.newTab();
    tabC.setText(getString(R.string.TabChuid_Title));
    tabC.setTabListener(this);
    actionBar.addTab(tabC);

    // this one will become the APDU log tab
    // only set up the tab is the preferences for Show Log = True

    if (showLog) {
        Tab tabD = actionBar.newTab();
        tabD.setText(getString(R.string.TabLog_Title));
        tabD.setTabListener(this);
        actionBar.addTab(tabD);
    }
}

From source file:org.esupportail.nfctagdroid.NfcTacDroidActivity.java

@Override
public void onResume() {
    super.onResume();
    log.info("App is resume");
    view.onResume();/*from  ww w  . j a va  2s .c o m*/
    view.loadUrl(url);
    view.resumeTimers();
    ESUP_NFC_TAG_SERVER_URL = getEsupNfcTagServerUrl(getApplicationContext());
    checkHardware(mAdapter);
    mAdapter.enableReaderMode(this, this,
            NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS, null);
}