@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launcher); pendingIntent = PendingIntent.getActivity(this, 0, new Intent("de.Ox539.kitcard.reader.TECH_DISCOVERED").addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); final IntentFilter intentFilter = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); intentFiltersArray = new IntentFilter[] { intentFilter }; techListsArray = new String[][] { new String[] { MifareClassic.class.getName() } }; NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE); adapter = manager.getDefaultAdapter(); if (!adapter.isEnabled()) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.activate_nfc), Toast.LENGTH_LONG).show(); startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS)); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); euroFormat = new EuroFormat(); pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); final IntentFilter intentFilter = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); intentFiltersArray = new IntentFilter[] { intentFilter }; techListsArray = new String[][] { new String[] { MifareClassic.class.getName() } }; setContentView(R.layout.activity_scan); resolveIntent(getIntent()); setTitle(getResources().getString(R.string.app_name)); NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE); adapter = manager.getDefaultAdapter(); if (!adapter.isEnabled()) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.activate_nfc), Toast.LENGTH_LONG).show(); startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS)); } }
@Override protected void onCreate(Bundle savedInstanceState) { setTheme(R.style.AppTheme); super.onCreate(savedInstanceState); mRealmRawData = Realm.getInstance(realmConfigRawData); mRealmProcessedData = Realm.getInstance(realmConfigProcessedData); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Create the adapter that will return a fragment for each of the // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), getApplicationContext()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(mSectionsPagerAdapter); TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.setupWithViewPager(mViewPager); mNfcAdapter = ((NfcManager) this.getSystemService(Context.NFC_SERVICE)).getDefaultAdapter(); if (mNfcAdapter != null) { Log.d(LOG_ID, "Got NFC adapter"); if (!mNfcAdapter.isEnabled()) { Toast.makeText(this, getResources().getString(R.string.error_nfc_disabled), Toast.LENGTH_LONG).show(); } } else { Log.e(LOG_ID,"No NFC adapter found!"); Toast.makeText(this, getResources().getString(R.string.error_nfc_device_not_supported), Toast.LENGTH_LONG).show(); } }
/** * Current NFC hardware state. Needs correct permission to work. * * @param context * @return state */ //@RequiresPermission(Manifest.permission.NFC) public static Status getNfcState(Context context) { NfcManager nfcManager = (NfcManager) context.getSystemService(Context.NFC_SERVICE); NfcAdapter adapter = nfcManager.getDefaultAdapter(); if (adapter == null) { return Status.UNSUPPORTED; } else if (ContextCompat.checkSelfPermission(context, Manifest.permission.NFC) != PackageManager.PERMISSION_GRANTED) { return Status.NEEDS_PERMISSION; } else if (adapter.isEnabled()) { return Status.ENABLED; } else { return Status.DISABLED; } }
public static boolean hasNFC(Context context) { boolean bRet = false; NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE); NfcAdapter adapter = manager.getDefaultAdapter(); if (adapter != null) { bRet = true; } return bRet; }
public static boolean isOpen(Context context) { boolean state = false; NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE); NfcAdapter adapter = manager.getDefaultAdapter(); if (adapter != null && adapter.isEnabled()) { state = true; } return state; }
public static boolean hasNfc(Context context) { try { NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE); NfcAdapter adapter = manager.getDefaultAdapter(); return adapter != null; } catch (Exception | Error e) { e.printStackTrace(); } return false; }
/** * Checks if the user has NFC and if it is enabled. * * If it is not enabled, {@link #openNFCDialog()} gets called. */ private void checkNFC() { NfcManager manager = (NfcManager) getApplicationContext().getSystemService(Context.NFC_SERVICE); NfcAdapter adapter = manager.getDefaultAdapter(); if (adapter != null ) { if (!adapter.isEnabled()) { Log.v(Global.DEBUG_TAG, "NFC is not activated"); openNFCDialog(); } } }
/** * Updates the NFC Status */ @TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1) private void updateNFCStatusDisplay() { final NfcManager nfcManager = (NfcManager) getActivity().getSystemService(Context.NFC_SERVICE); final NfcAdapter adapter = nfcManager.getDefaultAdapter(); nfc.setText(Boolean.toString(adapter != null && adapter.isEnabled())); }
@Override protected void onResume() { super.onResume(); NfcManager nMan = (NfcManager) this .getSystemService(Context.NFC_SERVICE); mNfcAdapter = nMan.getDefaultAdapter(); PendingIntent pi = createPendingResult(PENDING_INTENT_TECH_DISCOVERED, new Intent(), 0); mNfcAdapter .enableForegroundDispatch( this, pi, new IntentFilter[] { new IntentFilter( NfcAdapter.ACTION_TECH_DISCOVERED) }, new String[][] { new String[] { android.nfc.tech.MifareClassic.class .getName() }, new String[] { android.nfc.tech.IsoDep.class .getName() } }); if (mTerminal == null) { mTerminal = // new OpenMobileAPITerminal(this, this); NfcTerminal.getInstance(this); } mTCPConnection = new TCPConnection(this, this); Thread td = new Thread(mTCPConnection); td.start(); }
/** * Checks the IDs for Bluetooth and Wi-Fi scan sensors. * * @param deviceUuid * @param deviceType * @return true if all sensor IDs are found or created */ @TargetApi(10) private boolean checkDeviceScanSensors(String deviceType, String deviceUuid) { // preallocate objects boolean success = true; // match Bluetooth scan success &= checkSensor(SensorNames.BLUETOOTH_DISCOVERY, "bluetooth scan", SenseDataTypes.JSON, SensorNames.BLUETOOTH_DISCOVERY, "{\"name\":\"string\",\"address\":\"string\",\"rssi\":0}", deviceType, deviceUuid); // match Bluetooth neighbours count success &= checkSensor(SensorNames.BLUETOOTH_NEIGHBOURS_COUNT, "bluetooth neighbours count", SenseDataTypes.INT, SensorNames.BLUETOOTH_NEIGHBOURS_COUNT, "0", deviceType, deviceUuid); // match Wi-Fi scan success &= checkSensor( SensorNames.WIFI_SCAN, "wi-fi scan", SenseDataTypes.JSON, SensorNames.WIFI_SCAN, "{\"ssid\":\"string\",\"bssid\":\"string\",\"frequency\":0,\"rssi\":0,\"capabilities\":\"string\"}", deviceType, deviceUuid); // match NFC scan if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) { NfcManager nm = (NfcManager) getContext().getSystemService(Context.NFC_SERVICE); if (null != nm.getDefaultAdapter()) { success &= checkSensor(SensorNames.NFC_SCAN, "nfc scan", SenseDataTypes.JSON, SensorNames.NFC_SCAN, "{\"id\":\"string\",\"technology\":\"string\",\"message\":\"string\"}", deviceType, deviceUuid); } } return success; }
private void switchToNfcIfAvailable() { NfcManager manager = (NfcManager) getActivity().getSystemService(Context.NFC_SERVICE); NfcAdapter adapter = manager.getDefaultAdapter(); if (adapter != null && adapter.isEnabled()) { // nfc exists and is enabled. ivNfcIcon.setVisibility(View.VISIBLE); tvNfcExplanation.setVisibility(View.VISIBLE); btnReachedDestination.setVisibility(View.GONE); } }
/** * Checks the IDs for Bluetooth and Wi-Fi scan sensors. * * @param deviceUuid * @param deviceType * * @return true if all sensor IDs are found or created */ @TargetApi(10) private boolean checkDeviceScanSensors(String deviceType, String deviceUuid) { // preallocate objects boolean success = true; // match Bluetooth scan success &= checkSensor(SensorNames.BLUETOOTH_DISCOVERY, "bluetooth scan", SenseDataTypes.JSON, SensorNames.BLUETOOTH_DISCOVERY, "{\"name\":\"string\",\"address\":\"string\",\"rssi\":0}", deviceType, deviceUuid); // match Bluetooth neighbours count success &= checkSensor(SensorNames.BLUETOOTH_NEIGHBOURS_COUNT, "bluetooth neighbours count", SenseDataTypes.INT, SensorNames.BLUETOOTH_NEIGHBOURS_COUNT, "0", deviceType, deviceUuid); // match Wi-Fi scan success &= checkSensor( SensorNames.WIFI_SCAN, "wi-fi scan", SenseDataTypes.JSON, SensorNames.WIFI_SCAN, "{\"ssid\":\"string\",\"bssid\":\"string\",\"frequency\":0,\"rssi\":0,\"capabilities\":\"string\"}", deviceType, deviceUuid); // match NFC scan if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) { NfcManager nm = (NfcManager) getContext().getSystemService(Context.NFC_SERVICE); if (null != nm.getDefaultAdapter()) { success &= checkSensor(SensorNames.NFC_SCAN, "nfc scan", SenseDataTypes.JSON, SensorNames.NFC_SCAN, "{\"id\":\"string\",\"technology\":\"string\",\"message\":\"string\"}", deviceType, deviceUuid); } } return success; }
private Fragment getFragment() { NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE); NfcAdapter adapter = manager.getDefaultAdapter(); if (adapter == null) { return new NFCUnsupportedFragment(); } else if (!adapter.isEnabled()) { return new NFCDisabledFragment(); } else { return new NFCWriteTageFragment(); } }
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (AbstractBindServiceActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.wallet = application.getWallet(); this.prefs = PreferenceManager.getDefaultSharedPreferences(activity); this.loaderManager = getLoaderManager(); this.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE); this.clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); }
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (FragmentActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.prefs = PreferenceManager.getDefaultSharedPreferences(activity); this.nfcManager = (NfcManager) activity .getSystemService(Context.NFC_SERVICE); }
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (AbstractWalletActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.wallet = application.getWallet(); this.prefs = PreferenceManager.getDefaultSharedPreferences(activity); this.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE); this.resolver = activity.getContentResolver(); this.loaderManager = getLoaderManager(); }
public static boolean publishUri(@Nullable final NfcManager nfcManager, final Activity activity, @Nonnull final String uri) { if (nfcManager == null) return false; final NfcAdapter adapter = nfcManager.getDefaultAdapter(); if (adapter == null) return false; final NdefRecord uriRecord = wellKnownUriRecord(uri); adapter.enableForegroundNdefPush(activity, ndefMessage(uriRecord, true, activity.getPackageName())); return true; }
public static boolean publishMimeObject(@Nullable final NfcManager nfcManager, final Activity activity, @Nonnull final String mimeType, @Nonnull final byte[] payload, final boolean includeApplicationRecord) { if (nfcManager == null) return false; final NfcAdapter adapter = nfcManager.getDefaultAdapter(); if (adapter == null) return false; final NdefRecord mimeRecord = mimeRecord(mimeType, payload); adapter.enableForegroundNdefPush(activity, ndefMessage(mimeRecord, includeApplicationRecord, activity.getPackageName())); return true; }
public static void unpublish(@Nullable final NfcManager nfcManager, final Activity activity) { if (nfcManager == null) return; final NfcAdapter adapter = nfcManager.getDefaultAdapter(); if (adapter == null) return; adapter.disableForegroundNdefPush(activity); }
/** * Check if NFC is supported by this Smartphone. * * @return True if NFC is supported, else false. */ private boolean checkNFCSupport() { NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE); NfcAdapter adapter = manager.getDefaultAdapter(); if (adapter == null || !adapter.isEnabled()) { return false; } return true; }
public static boolean publishUri(final Object nfcManager, final Activity activity, final String uri) { final NfcAdapter adapter = ((NfcManager) nfcManager).getDefaultAdapter(); if (adapter == null) return false; final NdefRecord uriRecord = wellKnownUriRecord(uri); adapter.enableForegroundNdefPush(activity, ndefMessage(uriRecord, true, activity.getPackageName())); return true; }
public static boolean publishMimeObject(final Object nfcManager, final Activity activity, final String mimeType, final byte[] payload, final boolean includeApplicationRecord) { final NfcAdapter adapter = ((NfcManager) nfcManager).getDefaultAdapter(); if (adapter == null) return false; final NdefRecord mimeRecord = mimeRecord(mimeType, payload); adapter.enableForegroundNdefPush(activity, ndefMessage(mimeRecord, includeApplicationRecord, activity.getPackageName())); return true; }
public static void unpublish(final Object nfcManager, final Activity activity) { final NfcAdapter adapter = ((NfcManager) nfcManager).getDefaultAdapter(); if (adapter == null) return; adapter.disableForegroundNdefPush(activity); }
private boolean isNfcAvailable() { NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE); NfcAdapter adapter = manager.getDefaultAdapter(); if (adapter != null) { return true; } return false; }
/** * 返回 {@link NfcManager} */ public static NfcManager getNfcManager() { return (NfcManager) get(NFC_SERVICE); }
private static boolean hasNFC(Context context) { NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE); NfcAdapter adapter = manager.getDefaultAdapter(); return adapter != null; }
private static boolean isNFCEnabled(Context context) { NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE); NfcAdapter adapter = manager.getDefaultAdapter(); return adapter != null && adapter.isEnabled(); }
public NfcIconData(Context context) { super(context); manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE); }
@TargetApi(10) public static NfcManager getNfcManager() { return (NfcManager) getSystemService(Context.NFC_SERVICE); }
public static NfcManager nfc(Context context) { return (NfcManager) context.getSystemService(NFC_SERVICE); }
public static boolean isNfcEnabled(Context c){ NfcAdapter adapter = ((NfcManager) c.getSystemService(Context.NFC_SERVICE)).getDefaultAdapter(); return (adapter != null && adapter.isEnabled()); }
@Provides @Singleton public NfcManager provideNfcManager(final Application application) { return getSystemService(application, Context.NFC_SERVICE); }
@Override protected void onUpdateData(int intReason) { Log.d(getTag(), "Fetching near-field communication information"); ExtensionData edtInformation = new ExtensionData(); setUpdateWhenScreenOn(false); try { NfcManager nfcManager = (NfcManager) getSystemService(Context.NFC_SERVICE); if (nfcManager != null && nfcManager.getDefaultAdapter() != null) { Log.d(getTag(), "Checking if near-field communication is enabled"); if (nfcManager.getDefaultAdapter().isEnabled()) { Log.d(getTag(), "Near-field communication is enabled"); edtInformation.visible(true); edtInformation.status(getString(R.string.title)); edtInformation.clickIntent(new Intent("android.settings.NFC_SETTINGS")); if (nfcManager.getDefaultAdapter().isNdefPushEnabled()) { edtInformation.expandedBody(getString(R.string.beam_enabled)); } else { edtInformation.expandedBody(getString(R.string.beam_disabled)); } } else { Log.d(getTag(), "Near-field communication is disabled"); } } else { Log.d(getTag(), "Device doesn't support near-field communication"); } } catch (Exception e) { edtInformation.visible(false); Log.e(getTag(), "Encountered an error", e); ACRA.getErrorReporter().handleSilentException(e); } edtInformation.icon(R.drawable.ic_dashclock); doUpdate(edtInformation); }
public static NfcManager nfcManager() { return (NfcManager) get(Context.NFC_SERVICE); }
/** * Obtain a {@link NfcManager} instance associated with specified {@link Context} * * @param context Context * @return {@link NfcManager} associated with specified {@link Context} * @throws InvalidContextException if {@link NfcManager} can't be obtained * from specified {@link Context} */ @NonNull public static NfcManager getNfcManager(@NonNull Context context) { return validate(context.getSystemService(Context.NFC_SERVICE)); }