当前位置: 首页>>代码示例>>Java>>正文


Java NfcManager类代码示例

本文整理汇总了Java中android.nfc.NfcManager的典型用法代码示例。如果您正苦于以下问题:Java NfcManager类的具体用法?Java NfcManager怎么用?Java NfcManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NfcManager类属于android.nfc包,在下文中一共展示了NfcManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import android.nfc.NfcManager; //导入依赖的package包/类
@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));
    }
}
 
开发者ID:pkern,项目名称:kitcard-reader,代码行数:20,代码来源:MainActivity.java

示例2: onCreate

import android.nfc.NfcManager; //导入依赖的package包/类
@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));
    }
}
 
开发者ID:pkern,项目名称:kitcard-reader,代码行数:23,代码来源:ScanActivity.java

示例3: onCreate

import android.nfc.NfcManager; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:DorianScholz,项目名称:OpenLibre,代码行数:34,代码来源:MainActivity.java

示例4: getNfcState

import android.nfc.NfcManager; //导入依赖的package包/类
/**
 * 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;
    }
}
 
开发者ID:patrickfav,项目名称:under-the-hood,代码行数:21,代码来源:DeviceStatusUtil.java

示例5: hasNFC

import android.nfc.NfcManager; //导入依赖的package包/类
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;
}
 
开发者ID:backkomyoung,项目名称:Metro,代码行数:13,代码来源:NFCUtil.java

示例6: isOpen

import android.nfc.NfcManager; //导入依赖的package包/类
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;
}
 
开发者ID:backkomyoung,项目名称:Metro,代码行数:13,代码来源:NFCUtil.java

示例7: hasNfc

import android.nfc.NfcManager; //导入依赖的package包/类
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;
}
 
开发者ID:jszczygiel,项目名称:android-common,代码行数:11,代码来源:SystemHelper.java

示例8: checkNFC

import android.nfc.NfcManager; //导入依赖的package包/类
/**
 * 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();
        }
    }
}
 
开发者ID:xamoom,项目名称:xamoom-pingeborg-android,代码行数:16,代码来源:MainActivity.java

示例9: updateNFCStatusDisplay

import android.nfc.NfcManager; //导入依赖的package包/类
/**
 * 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()));
}
 
开发者ID:awslabs,项目名称:aws-device-farm-sample-app-for-android,代码行数:10,代码来源:FixturesFragment.java

示例10: onResume

import android.nfc.NfcManager; //导入依赖的package包/类
@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();
}
 
开发者ID:mobilesec,项目名称:secure-element-gpdroid-nfc,代码行数:30,代码来源:MainActivity.java

示例11: checkDeviceScanSensors

import android.nfc.NfcManager; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:swandroid,项目名称:swan-sense-studio,代码行数:46,代码来源:DefaultSensorRegistrator.java

示例12: switchToNfcIfAvailable

import android.nfc.NfcManager; //导入依赖的package包/类
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);
    }
}
 
开发者ID:AMOS-2015,项目名称:amos-ss15-proj2,代码行数:11,代码来源:JoinDrivingFragment.java

示例13: checkDeviceScanSensors

import android.nfc.NfcManager; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:nadinasovaiala,项目名称:swan_sense_integration,代码行数:47,代码来源:DefaultSensorRegistrator.java

示例14: getFragment

import android.nfc.NfcManager; //导入依赖的package包/类
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();
    }
}
 
开发者ID:openhab,项目名称:openhab-android,代码行数:14,代码来源:OpenHABWriteTagActivity.java

示例15: onAttach

import android.nfc.NfcManager; //导入依赖的package包/类
@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();
}
 
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:15,代码来源:RequestCoinsFragment.java


注:本文中的android.nfc.NfcManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。