本文整理汇总了Java中android.nfc.NfcAdapter.isEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java NfcAdapter.isEnabled方法的具体用法?Java NfcAdapter.isEnabled怎么用?Java NfcAdapter.isEnabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.nfc.NfcAdapter
的用法示例。
在下文中一共展示了NfcAdapter.isEnabled方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareNfcMenuItems
import android.nfc.NfcAdapter; //导入方法依赖的package包/类
@TargetApi(16)
private void prepareNfcMenuItems(Menu menu) {
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
MenuItem menuItem = menu.findItem(R.id.menu_enable_nfc);
if (nfcAdapter == null) {
menuItem.setVisible(false);
return;
}
boolean needsEnableNfcMenuItem;
if (Build.VERSION.SDK_INT < 16) {
needsEnableNfcMenuItem = !nfcAdapter.isEnabled();
} else {
needsEnableNfcMenuItem = !nfcAdapter.isNdefPushEnabled();
}
menuItem.setVisible(needsEnableNfcMenuItem);
}
示例2: onCreate
import android.nfc.NfcAdapter; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
Intent intent = getIntent();
String action = intent.getAction();
if (action != null) {
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action) || NfcAdapter.ACTION_TECH_DISCOVERED.equals(action) || NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {
if (nfcAdapter != null && nfcAdapter.isEnabled()) {
if (((OneSheeldApplication) getApplication()).getRunningShields().get(UIShield.NFC_SHIELD.name()) != null) {
((NfcShield) ((OneSheeldApplication) getApplication()).getRunningShields().get(UIShield.NFC_SHIELD.name())).handleIntent(intent);
}
} else {
Toast.makeText(getApplicationContext(), R.string.nfc_nfc_disabled_toast, Toast.LENGTH_SHORT).show();
}
} else {
startActivity(new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
}
} else
startActivity(new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
}
finish();
}
示例3: registerNFCListener
import android.nfc.NfcAdapter; //导入方法依赖的package包/类
public void registerNFCListener(boolean isToastable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
if (nfcAdapter != null && nfcAdapter.isEnabled()) {
setupForegroundDispatch();
selectionAction.onSuccess();
} else {
if(nfcAdapter == null){
if (isToastable) {
activity.showToast(R.string.nfc_device_doesnt_support_nfc);
}
}
else {
showSettingsDialogIfNfcIsNotEnabled();
}
selectionAction.onFailure();
}
} else {
if (isToastable)
activity.showToast(R.string.nfc_device_doesnt_support_nfc);
selectionAction.onFailure();
}
}
示例4: doOnJellybean
import android.nfc.NfcAdapter; //导入方法依赖的package包/类
@TargetApi(16)
private void doOnJellybean(Intent intent) {
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter == null) {
return;
}
if (nfcAdapter.isEnabled()) {
intent.setAction(Settings.ACTION_NFCSHARING_SETTINGS);
} else {
intent.setAction(Settings.ACTION_NFC_SETTINGS);
}
}
示例5: getNfcStatus
import android.nfc.NfcAdapter; //导入方法依赖的package包/类
private String getNfcStatus() {
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
if (nfcAdapter == null) {
return STATUS_NO_NFC;
} else if (!nfcAdapter.isEnabled()) {
return STATUS_NFC_DISABLED;
} else {
return STATUS_NFC_OK;
}
}