Search in sources :

Example 1 with NfcAdapter

use of android.nfc.NfcAdapter in project Android-Developers-Samples by johnjohndoe.

the class CardReaderFragment method enableReaderMode.

private void enableReaderMode() {
    Log.i(TAG, "Enabling reader mode");
    Activity activity = getActivity();
    NfcAdapter nfc = NfcAdapter.getDefaultAdapter(activity);
    if (nfc != null) {
        nfc.enableReaderMode(activity, mLoyaltyCardReader, READER_FLAGS, null);
    }
}
Also used : Activity(android.app.Activity) NfcAdapter(android.nfc.NfcAdapter)

Example 2 with NfcAdapter

use of android.nfc.NfcAdapter in project Android-Developers-Samples by johnjohndoe.

the class CardReaderFragment method disableReaderMode.

private void disableReaderMode() {
    Log.i(TAG, "Disabling reader mode");
    Activity activity = getActivity();
    NfcAdapter nfc = NfcAdapter.getDefaultAdapter(activity);
    if (nfc != null) {
        nfc.disableReaderMode(activity);
    }
}
Also used : Activity(android.app.Activity) NfcAdapter(android.nfc.NfcAdapter)

Example 3 with NfcAdapter

use of android.nfc.NfcAdapter in project weiciyuan by qii.

the class MainTimeLineParentActivity method initNFC.

private void initNFC() {
    NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null) {
        return;
    }
    mNfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {

        @Override
        public NdefMessage createNdefMessage(NfcEvent event) {
            String text = (GlobalContext.getInstance().getCurrentAccountName());
            NdefMessage msg = new NdefMessage(new NdefRecord[] { createMimeRecord("application/org.qii.weiciyuan.beam", text.getBytes()), NdefRecord.createApplicationRecord(getPackageName()) });
            return msg;
        }
    }, this);
}
Also used : NdefRecord(android.nfc.NdefRecord) NfcEvent(android.nfc.NfcEvent) NdefMessage(android.nfc.NdefMessage) NfcAdapter(android.nfc.NfcAdapter)

Example 4 with NfcAdapter

use of android.nfc.NfcAdapter in project robolectric by robolectric.

the class ShadowNfcAdapterTest method setNdefPushMesageCallback_shouldUseCallback.

@Test
public void setNdefPushMesageCallback_shouldUseCallback() {
    final NfcAdapter.CreateNdefMessageCallback callback = mock(NfcAdapter.CreateNdefMessageCallback.class);
    final Activity activity = Robolectric.setupActivity(Activity.class);
    final NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity);
    adapter.setNdefPushMessageCallback(callback, activity);
    assertThat(shadowOf(adapter).getNdefPushMessageCallback()).isSameAs(callback);
}
Also used : Activity(android.app.Activity) NfcAdapter(android.nfc.NfcAdapter) Test(org.junit.Test)

Example 5 with NfcAdapter

use of android.nfc.NfcAdapter in project platform_frameworks_base by android.

the class CardEmulation method recoverService.

void recoverService() {
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mContext);
    sService = adapter.getCardEmulationService();
}
Also used : NfcAdapter(android.nfc.NfcAdapter)

Aggregations

NfcAdapter (android.nfc.NfcAdapter)22 Activity (android.app.Activity)4 NdefMessage (android.nfc.NdefMessage)3 NdefRecord (android.nfc.NdefRecord)3 NfcEvent (android.nfc.NfcEvent)2 SuppressLint (android.annotation.SuppressLint)1 Fragment (android.app.Fragment)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 ResolveInfo (android.content.pm.ResolveInfo)1 Resources (android.content.res.Resources)1 WifiConfiguration (android.net.wifi.WifiConfiguration)1 Tag (android.nfc.Tag)1 Bundle (android.os.Bundle)1 UserManager (android.os.UserManager)1 PreferenceFragment (android.preference.PreferenceFragment)1 Preference (android.support.v7.preference.Preference)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1