Java 类android.nfc.NfcManager 实例源码

项目:kitcard-reader    文件:MainActivity.java   
@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));
    }
}
项目:kitcard-reader    文件:ScanActivity.java   
@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));
    }
}
项目:OpenLibre    文件:MainActivity.java   
@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();
    }
}
项目:under-the-hood    文件:DeviceStatusUtil.java   
/**
 * 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;
    }
}
项目:Metro    文件:NFCUtil.java   
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;
}
项目:Metro    文件:NFCUtil.java   
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;
}
项目:android-common    文件:SystemHelper.java   
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;
}
项目:xamoom-pingeborg-android    文件:MainActivity.java   
/**
 * 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();
        }
    }
}
项目:aws-device-farm-sample-app-for-android    文件:FixturesFragment.java   
/**
 * 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()));
}
项目:secure-element-gpdroid-nfc    文件:MainActivity.java   
@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();
}
项目:swan-sense-studio    文件:DefaultSensorRegistrator.java   
/**
 * 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;
}
项目:amos-ss15-proj2    文件:JoinDrivingFragment.java   
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);
    }
}
项目:swan_sense_integration    文件:DefaultSensorRegistrator.java   
/**
 * 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;
}
项目:openhab-android    文件:OpenHABWriteTagActivity.java   
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();
    }
}
项目:templecoin-android-wallet    文件:RequestCoinsFragment.java   
@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();
}
项目:templecoin-android-wallet    文件:WalletAddressFragment.java   
@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);
}
项目:templecoin-android-wallet    文件:TransactionsListFragment.java   
@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();
}
项目:templecoin-android-wallet    文件:Nfc.java   
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;
}
项目:templecoin-android-wallet    文件:Nfc.java   
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;
}
项目:templecoin-android-wallet    文件:Nfc.java   
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);
}
项目:irma_future_id    文件:TerminalFactoryActivity.java   
/**
    * 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;
   }
项目:goldcoin-android    文件:NfcTools.java   
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;
}
项目:goldcoin-android    文件:NfcTools.java   
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;
}
项目:goldcoin-android    文件:NfcTools.java   
public static void unpublish(final Object nfcManager, final Activity activity)
{
    final NfcAdapter adapter = ((NfcManager) nfcManager).getDefaultAdapter();
    if (adapter == null)
        return;

    adapter.disableForegroundNdefPush(activity);
}
项目:godot-android    文件:MainActivity.java   
private boolean isNfcAvailable() {
    NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE);
    NfcAdapter adapter = manager.getDefaultAdapter();
    if (adapter != null) {
        return true;
    }

    return false;
}
项目:EasyAndroid    文件:Managers.java   
/**
 * 返回 {@link NfcManager}
 */
public static NfcManager getNfcManager()
{
    return (NfcManager) get(NFC_SERVICE);
}
项目:coinblesk-client-gui    文件:UIUtils.java   
private static boolean hasNFC(Context context) {
    NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
    NfcAdapter adapter = manager.getDefaultAdapter();
    return adapter != null;
}
项目:coinblesk-client-gui    文件:UIUtils.java   
private static boolean isNFCEnabled(Context context) {
    NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
    NfcAdapter adapter = manager.getDefaultAdapter();
    return adapter != null && adapter.isEnabled();
}
项目:Status    文件:NfcIconData.java   
public NfcIconData(Context context) {
    super(context);
    manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
}
项目:Android-App-Template    文件:ServiceUtil.java   
@TargetApi(10)
public static NfcManager getNfcManager() {
    return (NfcManager) getSystemService(Context.NFC_SERVICE);
}
项目:sprockets-android    文件:Managers.java   
public static NfcManager nfc(Context context) {
    return (NfcManager) context.getSystemService(NFC_SERVICE);
}
项目:CampusCardReader    文件:Helper.java   
public static boolean isNfcEnabled(Context c){
    NfcAdapter adapter = ((NfcManager) c.getSystemService(Context.NFC_SERVICE)).getDefaultAdapter();
    return (adapter != null && adapter.isEnabled());
}
项目:stabbed-android    文件:DefaultAndroidApplicationModule.java   
@Provides
@Singleton
public NfcManager provideNfcManager(final Application application) {
    return getSystemService(application, Context.NFC_SERVICE);
}
项目:dashclock-fielder    文件:FielderWidget.java   
@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);

}
项目:android_Skeleton    文件:SystemServices.java   
public static NfcManager nfcManager() {
    return (NfcManager) get(Context.NFC_SERVICE);
}
项目:android-wheels    文件:ContextUtils.java   
/**
 * 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));
}