本文整理匯總了Java中android.nfc.NfcAdapter.getDefaultAdapter方法的典型用法代碼示例。如果您正苦於以下問題:Java NfcAdapter.getDefaultAdapter方法的具體用法?Java NfcAdapter.getDefaultAdapter怎麽用?Java NfcAdapter.getDefaultAdapter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.nfc.NfcAdapter
的用法示例。
在下文中一共展示了NfcAdapter.getDefaultAdapter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: enableDisableForegroundDispatch
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
private void enableDisableForegroundDispatch(boolean enable) {
Log.i(LOG_TAG, "enableForegroundDispatch, enable = " + enable);
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
Activity currentActivity = getCurrentActivity();
if (nfcAdapter != null && !currentActivity.isFinishing()) {
try {
if (enable) {
nfcAdapter.enableForegroundDispatch(currentActivity, getPendingIntent(), getIntentFilters(), getTechLists());
} else {
nfcAdapter.disableForegroundDispatch(currentActivity);
}
} catch (IllegalStateException e) {
Log.w(LOG_TAG, "Illegal State Exception starting NFC. Assuming application is terminating.");
}
}
}
示例2: onCreate
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pendingIntent = PendingIntent.getActivity(
this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter mifare = new IntentFilter((NfcAdapter.ACTION_TECH_DISCOVERED));
filters = new IntentFilter[] { mifare };
techs = new String[][] { new String[] {NfcA.class.getName() } };
if(adapter==null)
{
adapter = NfcAdapter.getDefaultAdapter(this);
}
imageView = (ImageView) findViewById(R.id.imageView);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation rotation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotation);
imageView.startAnimation(rotation);
}
});
}
示例3: 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);
}
示例4: onCreate
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
mAdapter = NfcAdapter.getDefaultAdapter(this);
// Create an NDEF message a URL
mMessage = new NdefMessage(NdefRecord.createUri("http://www.android.com"));
setContentView(R.layout.foreground_dispatch);
mText = (TextView) findViewById(R.id.text);
if (mAdapter != null) {
mAdapter.setNdefPushMessage(mMessage, this);
mText.setText("Tap another Android phone with NFC to push a URL");
} else {
mText.setText("This phone is not NFC enabled.");
}
}
示例5: onCreate
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
/**
* This activity usually be loaded from the starting screen of the app.
* This method handles the start-up of the activity, it does not need to call any other methods
* since the activity onNewIntent() calls the intentHandler when a NFC chip is detected.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
documentData = (DocumentData) extras.get(DocumentData.identifier);
thisActivity = this;
setContentView(R.layout.activity_passport_con);
Toolbar appBar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(appBar);
Util.setupAppBar(appBar, this);
TextView notice = (TextView) findViewById(R.id.notice);
progressView = (ImageView) findViewById(R.id.progress_view);
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
checkNFCStatus();
notice.setText(R.string.nfc_enabled);
}
示例6: 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();
}
}
示例7: registerForBeam
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
/**
* If the device has NFC, construct a BeamCallback and pass it to Android.
*
* @param activity Activity that is sending out beam messages.
* @param provider Provider that returns the URL that should be shared.
*/
public static void registerForBeam(final Activity activity, final BeamProvider provider) {
final NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
if (nfcAdapter == null) return;
if (ApiCompatibilityUtils.checkPermission(
activity, Manifest.permission.NFC, Process.myPid(), Process.myUid())
== PackageManager.PERMISSION_DENIED) {
return;
}
try {
final BeamCallback beamCallback = new BeamCallback(activity, provider);
nfcAdapter.setNdefPushMessageCallback(beamCallback, activity);
nfcAdapter.setOnNdefPushCompleteCallback(beamCallback, activity);
} catch (IllegalStateException e) {
Log.w("BeamController", "NFC registration failure. Can't retry, giving up.");
}
}
示例8: onCreate
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
cinemas = DBHelper.getInstance(getContext()).getCinemas();
watcher = new Gson().fromJson(getArguments().getString("watcher"), Watcher.class);
nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
if(nfcAdapter != null) {
nfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
@Override
public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
return new NdefMessage(
new NdefRecord[] {
NdefRecord.createUri(BuildConfig.SERVER_BASE_URL + "w/" + watcher.getID()),
NdefRecord.createApplicationRecord(BuildConfig.APPLICATION_ID)
}
);
}
}, getActivity());
}
}
示例9: nfcInit
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
private void nfcInit(){
TextView notice= (TextView) findViewById(R.id.nfc_notice);
// 監聽掃描NFC
IntentFilter ifilters=new IntentFilter();
ifilters.addAction(NfcAdapter.ACTION_NDEF_DISCOVERED); //NDEF
nfcAdapter=NfcAdapter.getDefaultAdapter(this);
pi=PendingIntent.getActivity(this,0,new Intent(this,getClass()),0);
if(nfcAdapter==null){
NFCSupport=false;
Toast.makeText(this,"Device dose not support NFC!",Toast.LENGTH_LONG).show();
notice.setText("Device dose not support NFC!");
}
else if(nfcAdapter!=null&&!nfcAdapter.isEnabled()){
NFCSupport=false;
Toast.makeText(this,"Please turn on NFC in your setting.",Toast.LENGTH_LONG).show();
notice.setText("Please turn on NFC in your setting.");
}
else{
NFCSupport=true;
}
}
示例10: 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();
}
示例11: runSetupSteps
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
@Override
public void runSetupSteps() throws RemoteConnectionException {
adapter = NfcAdapter.getDefaultAdapter(activity);
if (adapter == null) {
throw new RemoteConnectionException("NFC is not supported on this device.", false);
}
setupCompleted = true;
}
示例12: changeNfcState
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
private static void changeNfcState(Intent intent) {
if (mContext == null) return;
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mContext);
if (adapter == null) return;
try {
boolean enable = false;
if (intent.hasExtra(AShortcut.EXTRA_ENABLE)) {
enable = intent.getBooleanExtra(AShortcut.EXTRA_ENABLE, false);
} else {
int nfcState = (Integer) XposedHelpers.callMethod(adapter, "getAdapterState");
switch (nfcState) {
case NFC_STATE_TURNING_ON:
case NFC_STATE_ON:
enable = false;
break;
case NFC_STATE_TURNING_OFF:
case NFC_STATE_OFF:
enable = true;
break;
}
}
XposedHelpers.callMethod(adapter, enable ? "enable" : "disable");
if (intent.getBooleanExtra(AShortcut.EXTRA_SHOW_TOAST, false)) {
Utils.postToast(mContext, enable ? R.string.nfc_on : R.string.nfc_off);
}
} catch (Throwable t) {
XposedBridge.log(t);
}
}
示例13: isEnabled
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
@ReactMethod
public void isEnabled(Callback callback) {
Log.d(LOG_TAG, "isEnabled");
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
if (nfcAdapter != null) {
callback.invoke(null, nfcAdapter.isEnabled());
} else {
callback.invoke(null, false);
}
}
示例14: onCreate
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdapter=NfcAdapter.getDefaultAdapter(this);
if(mAdapter==null)
{
Toast.makeText(this, "No NFC found on this device", Toast.LENGTH_SHORT).show();
finish();
return;
}
mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
mICC = new IsoDepAdapter();
mCoreAdapter = new CoreAdapter(this);
mQPboc = new QPboc(mICC,mCoreAdapter);
//for test
mQPboc.setParam("123456789012345","12345678","BCTC","FFFFFFFF");
String field62 = "9F0608A000000333010101DF0101009F08020020DF1105D84000A800DF1205D84004F800DF130500100000009F1B0400000001DF150400000000DF160199DF170199DF14039F3704DF1801019F7B06000000100000DF1906000000100000DF2006000000100000DF2106000000100000";
//載入一個AID參數
mQPboc.updateAid(field62,true);
}
示例15: stopForegroundDispatch
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
public void stopForegroundDispatch() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
if (nfcAdapter != null) {
if (isForeground) {
nfcAdapter.disableForegroundDispatch(activity);
isForeground = false;
}
}
}
}