本文整理匯總了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;
}
}