本文整理汇总了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));
}
}
示例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));
}
}
示例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();
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
}
示例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()));
}
示例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();
}
示例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;
}
示例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);
}
}
示例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;
}
示例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();
}
}
示例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();
}