Android NfcAdapter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android NfcAdapter class.

This code example shows how to use the following methods:attemptDeadServiceRecovery, getNfcAdapterExtrasInterface
    private final NfcAdapter mAdapter;
    final String mPackageName;
 
    /** get service handles */ 
    private static void initService(NfcAdapter adapter) {
        final INfcAdapterExtras service = adapter.getNfcAdapterExtrasInterface();
        if (service != null) {
            // Leave stale rather than receive a null value. 
            sService = service;
        } 
    } 
 
    /** 
     * Get the {@link NfcAdapterExtras} for the given {@link NfcAdapter}. 
     * 
     * <p class="note"> 
     * Requires the {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} permission. 
     * 
     * @param adapter a {@link NfcAdapter}, must not be null 
     * @return the {@link NfcAdapterExtras} object for the given {@link NfcAdapter} 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:disableForegroundDispatch
        return PendingIntent.getActivity(this, 0,
                new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    } 
 
    private void disableTagWriteMode() { 
        mNfcAdapter.disableForegroundDispatch(this);
    } 
 
    private void enableTagWriteMode() { 
        IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
        mWriteTagFilters = new IntentFilter[] {
            tagDetected
        }; 
        mNfcAdapter.enableForegroundDispatch(this, getPendingIntent(), mWriteTagFilters, null);
    } 
 
    @Override 
    protected void onNewIntent(Intent intent) {
        // Tag writing mode 
        if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:disableForegroundDispatch, disableForegroundNdefPush
 
    @Override 
    protected void onPause() { 
        super.onPause(); 
        if (mAdapter != null) {
            mAdapter.disableForegroundDispatch(this);
            mAdapter.disableForegroundNdefPush(this);
        } 
    } 
 
    private void resolveIntent(Intent intent) {
        String action = intent.getAction();
        if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
                || NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)
                || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
            Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
            NdefMessage[] msgs;
            if (rawMsgs != null) {
                msgs = new NdefMessage[rawMsgs.length];
                for (int i = 0; i < rawMsgs.length; i++) {
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:disableForegroundDispatch
  } 
   
  @Override 
  public void onPause() { 
    if (isFinishing()) {
      nfc.disableForegroundDispatch(this);
      inWriteMode=false;
    } 
     
    super.onPause(); 
  } 
   
  private byte[] buildUrlBytes(String url) {
    byte prefixByte=0;
    String subset=url;
    int bestPrefixLength=0;
     
    for (int i=0;i<PREFIXES.length;i++) {
      String prefix = PREFIXES[i];
       
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isNdefPushEnabled
        } 
    } 
 
    private void initView(View view) {
        mActionBarSwitch.setOnCheckedChangeListener(this);
        mActionBarSwitch.setChecked(mNfcAdapter.isNdefPushEnabled());
    } 
 
    @Override 
    public void onCheckedChanged(CompoundButton buttonView, boolean desiredState) {
        boolean success = false;
        mActionBarSwitch.setEnabled(false);
        if (desiredState) {
            success = mNfcAdapter.enableNdefPush();
        } else { 
            success = mNfcAdapter.disableNdefPush();
        } 
        if (success) {
            mActionBarSwitch.setChecked(desiredState);
        } 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:enableForegroundDispatch
        IntentFilter[] filters = new IntentFilter[] { ndef };
        String[][] techLists = new  String[][] {
                new String[] { Ndef.class.getName() },
                new String[] { NdefFormatable.class.getName() }
        }; 
        mNfcAdapter.enableForegroundDispatch(this, pendingIntent, filters, techLists);
    } 
 
    @Override 
    protected void onPause() { 
        super.onPause(); 
        if (mNfcAdapter != null) {
            mNfcAdapter.disableForegroundDispatch(this);
        } 
    } 
 
    @Override 
    protected void onNewIntent(Intent intent) {
        switch (mTagToWrite) {
        case TAG_ALLOW:
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:enableForegroundDispatch
 
    @Override 
    protected void onResume() { 
        super.onResume(); 
        if (mNfcAdapter != null) {
            mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, null, mTechLists);
        } 
    } 
 
    @Override 
    protected void onPause() { 
        super.onPause(); 
        if (mNfcAdapter != null) {
            mNfcAdapter.disableForegroundDispatch(this);
        } 
    } 
 
    public void onSupportedCardsClick(View view) {
        startActivity(new Intent(this, SupportedCardsActivity.class));
    } 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isEnabled, setNdefPushMessageCallback, setOnNdefPushCompleteCallback
 
		mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
		if (mNfcAdapter == null) {
			mCallback.onNfcNotSupported();
			return; 
		} else if (mNfcAdapter.isEnabled() == false) {
			mCallback.onNfcDisabled();
		} 
 
		mNfcAdapter.setNdefPushMessageCallback(this, activity);
		mNfcAdapter.setOnNdefPushCompleteCallback(this, activity);
	} 
 
	/** 
	 * NdefMessageが要求された時 (=Beamで送るメッセージを要求された時) の動作. 
	 */ 
	@Override 
	public NdefMessage createNdefMessage(NfcEvent event) {
		NdefMessage msg = mCallback.onBeamSendPreprocess();
		return msg;
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:attemptDeadServiceRecovery, getNfcAdapterExtrasInterface
    private final NfcAdapter mAdapter;
    final String mPackageName;
 
    /** get service handles */ 
    private static void initService(NfcAdapter adapter) {
        final INfcAdapterExtras service = adapter.getNfcAdapterExtrasInterface();
        if (service != null) {
            // Leave stale rather than receive a null value. 
            sService = service;
        } 
    } 
 
    /** 
     * Get the {@link NfcAdapterExtras} for the given {@link NfcAdapter}. 
     * 
     * <p class="note"> 
     * Requires the {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} permission. 
     * 
     * @param adapter a {@link NfcAdapter}, must not be null 
     * @return the {@link NfcAdapterExtras} object for the given {@link NfcAdapter} 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:enableForegroundDispatch
	    }; 
	} 
 
	public void enableForeground() { 
		if (nfc != null) {
			nfc.enableForegroundDispatch(activity, intent, intentFilters, techLists);
		} 
	} 
 
	public void disableForeground() { 
		nfc.disableForegroundDispatch(activity);
	} 
 
	public NfcAdapter getNfc() {
	    return nfc;
	} 
 
	/** 
	 * Returns an instanceof a this class IF NFC privileges have been set. 
	 * @param moSync 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android NfcAdapter Questions & Answers:

See Code Examples for Android NfcAdapter Methods: