Search in sources :

Example 1 with NfcManager

use of android.nfc.NfcManager in project android_packages_apps_Settings by LineageOS.

the class ConnectedDeviceDashboardFragmentTest method testSummaryProvider_hasNfc_shouldReturnNfcSummary.

@Test
public void testSummaryProvider_hasNfc_shouldReturnNfcSummary() {
    final NfcManager nfcManager = mock(NfcManager.class);
    final SummaryLoader summaryLoader = mock(SummaryLoader.class);
    when(mContext.getApplicationContext()).thenReturn(mContext);
    when(mContext.getSystemService(NFC_SERVICE)).thenReturn(nfcManager);
    when(nfcManager.getDefaultAdapter()).thenReturn(mock(NfcAdapter.class));
    SummaryLoader.SummaryProvider provider = new ConnectedDeviceDashboardFragment.SummaryProvider(mContext, summaryLoader);
    provider.setListening(false);
    verifyZeroInteractions(summaryLoader);
    provider.setListening(true);
    verify(mContext).getString(R.string.connected_devices_dashboard_summary);
}
Also used : NfcManager(android.nfc.NfcManager) SummaryLoader(com.android.settings.dashboard.SummaryLoader) NfcAdapter(android.nfc.NfcAdapter) Test(org.junit.Test)

Example 2 with NfcManager

use of android.nfc.NfcManager in project android_packages_apps_Settings by omnirom.

the class ConnectedDeviceDashboardFragmentTest method testSummaryProvider_hasNfc_shouldReturnNfcSummary.

@Test
public void testSummaryProvider_hasNfc_shouldReturnNfcSummary() {
    final NfcManager nfcManager = mock(NfcManager.class);
    final SummaryLoader summaryLoader = mock(SummaryLoader.class);
    when(mContext.getApplicationContext()).thenReturn(mContext);
    when(mContext.getSystemService(NFC_SERVICE)).thenReturn(nfcManager);
    when(nfcManager.getDefaultAdapter()).thenReturn(mock(NfcAdapter.class));
    SummaryLoader.SummaryProvider provider = new ConnectedDeviceDashboardFragment.SummaryProvider(mContext, summaryLoader);
    provider.setListening(false);
    verifyZeroInteractions(summaryLoader);
    provider.setListening(true);
    verify(mContext).getString(R.string.connected_devices_dashboard_summary);
}
Also used : NfcManager(android.nfc.NfcManager) SummaryLoader(com.android.settings.dashboard.SummaryLoader) NfcAdapter(android.nfc.NfcAdapter) Test(org.junit.Test)

Example 3 with NfcManager

use of android.nfc.NfcManager in project xDrip by NightscoutFoundation.

the class NFCReaderX method doNFC.

@SuppressLint("NewApi")
public static void doNFC(final Activity context) {
    if (!useNFC())
        return;
    mNfcAdapter = NfcAdapter.getDefaultAdapter(context);
    try {
        if (mNfcAdapter == null) {
            JoH.static_toast_long("Phone has no NFC reader");
            // finish();
            return;
        } else if (!mNfcAdapter.isEnabled()) {
            JoH.static_toast_long("NFC is not enabled");
            return;
        }
    } catch (NullPointerException e) {
        JoH.static_toast_long("Phone NFC is having problems!");
        return;
    }
    nfc_enabled = true;
    NfcManager nfcManager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
    if (nfcManager != null) {
        mNfcAdapter = nfcManager.getDefaultAdapter();
    }
    if (mNfcAdapter != null) {
        try {
            mNfcAdapter.isEnabled();
        } catch (NullPointerException e) {
            return;
        }
        // some superstitious code here
        try {
            mNfcAdapter.isEnabled();
        } catch (NullPointerException e) {
            return;
        }
        if ((Build.VERSION.SDK_INT >= 19) && (useReaderMode)) {
            try {
                mNfcAdapter.disableReaderMode(context);
                final Bundle options = new Bundle();
                options.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 5000);
                mNfcAdapter.enableReaderMode(context, new NfcAdapter.ReaderCallback() {

                    @Override
                    public void onTagDiscovered(Tag tag) {
                        Log.d(TAG, "Reader mode tag discovered");
                        doTheScan(context, tag, false);
                    }
                }, NfcAdapter.FLAG_READER_NFC_V | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK | NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS, options);
            } catch (NullPointerException e) {
                Log.wtf(TAG, "Null pointer exception from NFC subsystem: " + e.toString());
            }
        } else {
            PendingIntent pi = context.createPendingResult(REQ_CODE_NFC_TAG_FOUND, new Intent(), 0);
            if (pi != null) {
                try {
                    mNfcAdapter.enableForegroundDispatch(context, pi, new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED) }, new String[][] { new String[] { "android.nfc.tech.NfcV" } });
                    foreground_enabled = true;
                } catch (NullPointerException e) {
                // 
                }
            }
        }
    }
}
Also used : IntentFilter(android.content.IntentFilter) Bundle(android.os.Bundle) NfcManager(android.nfc.NfcManager) NfcAdapter(android.nfc.NfcAdapter) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Tag(android.nfc.Tag) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint)

Example 4 with NfcManager

use of android.nfc.NfcManager in project android_packages_apps_Settings by crdroidandroid.

the class NfcPreferenceController method updateNonIndexableKeys.

@Override
public void updateNonIndexableKeys(List<String> keys) {
    final NfcManager manager = (NfcManager) mContext.getSystemService(Context.NFC_SERVICE);
    if (manager != null) {
        NfcAdapter adapter = manager.getDefaultAdapter();
        if (adapter == null) {
            keys.add(KEY_TOGGLE_NFC);
            keys.add(KEY_ANDROID_BEAM_SETTINGS);
        }
    }
}
Also used : NfcManager(android.nfc.NfcManager) NfcAdapter(android.nfc.NfcAdapter)

Example 5 with NfcManager

use of android.nfc.NfcManager in project android_packages_apps_Settings by SudaMod.

the class NfcPreferenceController method updateNonIndexableKeys.

@Override
public void updateNonIndexableKeys(List<String> keys) {
    final NfcManager manager = (NfcManager) mContext.getSystemService(Context.NFC_SERVICE);
    if (manager != null) {
        NfcAdapter adapter = manager.getDefaultAdapter();
        if (adapter == null) {
            keys.add(KEY_TOGGLE_NFC);
            keys.add(KEY_ANDROID_BEAM_SETTINGS);
        }
    }
}
Also used : NfcManager(android.nfc.NfcManager) NfcAdapter(android.nfc.NfcAdapter)

Aggregations

NfcManager (android.nfc.NfcManager)18 NfcAdapter (android.nfc.NfcAdapter)15 Test (org.junit.Test)7 SummaryLoader (com.android.settings.dashboard.SummaryLoader)6 Intent (android.content.Intent)3 SuppressLint (android.annotation.SuppressLint)2 PendingIntent (android.app.PendingIntent)2 IntentFilter (android.content.IntentFilter)2 Tag (android.nfc.Tag)2 Bundle (android.os.Bundle)2 LocationManager (android.location.LocationManager)1 AudioManager (android.media.AudioManager)1 ConnectivityManager (android.net.ConnectivityManager)1 WifiManager (android.net.wifi.WifiManager)1 UiObject2 (android.support.test.uiautomator.UiObject2)1 Toolbar (android.support.v7.widget.Toolbar)1 MediumTest (androidx.test.filters.MediumTest)1 AirplaneModeSettings (cyanogenmod.profiles.AirplaneModeSettings)1 ConnectionSettings (cyanogenmod.profiles.ConnectionSettings)1 RingModeSettings (cyanogenmod.profiles.RingModeSettings)1