NfcAdapter enableForegroundNdefPush - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:enableForegroundDispatch, enableForegroundNdefPush, isEnabled
    protected void onResume() { 
        // TODO Auto-generated method stub 
        super.onResume(); 
         
        // check if NFC is enabled on device 
        if(!mNfcAdapter.isEnabled()){
            //TODO enable nfc 
            System.out.println("NFC not enabled!");
        } 
         
        if(true){ 
            System.out.println("Start Transmitting..");
             
            String text=("Beam me up, Android! \n\n"+"Beam Time: "+ System.currentTimeMillis());
             
            NdefMessage msg=new NdefMessage(
                    new NdefRecord[]{     
                            new NdefRecord(
                            NdefRecord.TNF_WELL_KNOWN,
                            NdefRecord.RTD_TEXT,

5
CodeRank
This code example shows how to use the following methods:enableForegroundNdefPush, isEnabled, isNdefPushEnabled
 
    @Override 
    protected void onResume() { 
        super.onResume(); 
 
        if (!mNfcAdapter.isEnabled()) {
            showDialog(NFC_NOT_ENABLED_DIALOG_ID);
        } else if (!mNfcAdapter.isNdefPushEnabled()) {
            /* Sender must have NDEF push enabled */ 
            showDialog(NDEF_PUSH_NOT_ENABLED_DIALOG_ID);
        } 
 
        mNfcAdapter.enableForegroundNdefPush(this, TEST_MESSAGE);
    } 
 
    @Override 
    protected void onPause() { 
        super.onPause(); 
        mNfcAdapter.disableForegroundNdefPush(this);
    } 
5
CodeRank
This code example shows how to use the following methods:enableForegroundNdefPush
  } 
 
  public static void enableNFCWriteMode(Activity activity, NfcAdapter nfcAdapter, String textToWrite){
    NdefRecord textRecord = createTextRecord(textToWrite,true);
    NdefMessage msg = new NdefMessage(new NdefRecord[] { textRecord });
    nfcAdapter.enableForegroundNdefPush(activity, msg);
  } 
 
  public static void disableNFCAdapter(Activity activity, NfcAdapter nfcAdapter){
    nfcAdapter.disableForegroundNdefPush(activity);
  } 
 
  public static NdefRecord createTextRecord(String payload, boolean encodeInUtf8) {
    byte[] langBytes = Locale.getDefault().getLanguage().getBytes(Charset.forName("US-ASCII"));
    Charset utfEncoding = encodeInUtf8 ? Charset.forName("UTF-8") : Charset.forName("UTF-16");
    byte[] textBytes = payload.getBytes(utfEncoding);
    int utfBit = encodeInUtf8 ? 0 : (1 << 7);
    char status = (char) (utfBit + langBytes.length);
    byte[] data = new byte[1 + langBytes.length + textBytes.length];
    data[0] = (byte) status;
5
CodeRank
This code example shows how to use the following methods:enableForegroundDispatch, enableForegroundNdefPush
	} 
 
	@SuppressWarnings("deprecation") 
	private void enableNdefExchangeMode() { 
		nfcAdapter
				.enableForegroundNdefPush(PassFlagActivity.this, flagAsNdef());
		nfcAdapter.enableForegroundDispatch(this, nfcPendingIntent,
				ndefExchangeFilters, null);
	} 
} 
5
CodeRank
This code example shows how to use the following methods:enableForegroundDispatch, enableForegroundNdefPush
	    } 
	    //turn on ndef exchange after writing 
	    //called from prompt for content 
	    //leads to get note from ndef 
	    private void enableNdefExchangeMode() { 
	        mNfcAdapter.enableForegroundNdefPush(Meeting.this, getNoteAsNdef());
	        mNfcAdapter.enableForegroundDispatch(this, mNfcPendingIntent, mNdefExchangeFilters, null);
	    } 
	    //turn off ndef exchange before writing 
	    private void disableNdefExchangeMode() { 
	        mNfcAdapter.disableForegroundNdefPush(this);
	        mNfcAdapter.disableForegroundDispatch(this);
	    } 
	    //turn on tag writing after ndef exchange off 
	    private void enableTagWriteMode() { 
	        mWriteMode = true;
	        IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
	        mWriteTagFilters = new IntentFilter[] {
	            tagDetected
	        }; 
4
CodeRank
This code example shows how to use the following methods:enableForegroundDispatch, enableForegroundNdefPush
	} 
 
	private void enableNdefExchangeMode() { 
 
		Log.v(TAG, " Enable NDEF Exchange Mode ");
		mNfcAdapter.enableForegroundNdefPush(TapOnTagActivity.this, getNoteAsNdef());
		mNfcAdapter.enableForegroundDispatch(this, mNfcPendingIntent, mNdefExchangeFilters, null);
	} 
 
	private void disableNdefExchangeMode() { 
		mNfcAdapter.disableForegroundNdefPush(this);
		mNfcAdapter.disableForegroundDispatch(this);
	} 
 
	private void enableTagWriteMode() { 
		mWriteMode = true;
		IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
		mWriteTagFilters = new IntentFilter[] {
				tagDetected
		}; 
4
CodeRank
This code example shows how to use the following methods:enableForegroundDispatch, enableForegroundNdefPush
        } 
        return msgs;
    } 
 
    private void enableNdefExchangeMode() { 
        mNfcAdapter.enableForegroundNdefPush(SmartPoster.this, getNoteAsNdef());
        mNfcAdapter.enableForegroundDispatch(this, mNfcPendingIntent, mNdefExchangeFilters, null);
    } 
 
   /* private void disableNdefExchangeMode() { 
        mNfcAdapter.disableForegroundNdefPush(this); 
        mNfcAdapter.disableForegroundDispatch(this); 
    } 
*/ 
   /* private void enableTagWriteMode() { 
        mWriteMode = true; 
        IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); 
        mWriteTagFilters = new IntentFilter[] { 
            tagDetected 
        }; 
4
CodeRank
This code example shows how to use the following methods:enableForegroundDispatch, enableForegroundNdefPush
		} 
		return msgs;
	} 
 
	private void enableNdefExchangeMode() { 
		mNfcAdapter.enableForegroundNdefPush(this, getMsgAsNdef(mMsg));
		mNfcAdapter.enableForegroundDispatch(this, mNfcPendingIntent,
				mNdefExchangeFilters, null);
	} 
 
	boolean writeTag(NdefMessage message, Tag tag) {
		int size = message.toByteArray().length;
 
		try { 
			Ndef ndef = Ndef.get(tag);
			if (ndef != null) {
				ndef.connect();
 
				if (!ndef.isWritable()) {
					toast("Tag is read-only."); 
4
CodeRank
This code example shows how to use the following methods:enableForegroundDispatch, enableForegroundNdefPush
		return theMessage;
		 
	} 
 
	private void enableNdefExchangeMode() { 
	    mNfcAdapter.enableForegroundNdefPush(NFCOperation.this, createNFCMessage() );
	    mNfcAdapter.enableForegroundDispatch(this, mNfcPendingIntent, 
	        mNdefExchangeFilters, null);
	} 
	 
    private void disableNdefExchangeMode() { 
        mNfcAdapter.disableForegroundNdefPush(this);
        mNfcAdapter.disableForegroundDispatch(this);
    } 
	 
 
     
	public void onResume() { 
		super.onResume(); 
		 
4
CodeRank
This code example shows how to use the following methods:enableForegroundDispatch, enableForegroundNdefPush
	        } 
	        return msgs;
	    } 
 
	    private void enableNdefExchangeMode() { 
	        mNfcAdapter.enableForegroundNdefPush(MainActivity.this, getNoteAsNdef());
	        mNfcAdapter.enableForegroundDispatch(this, mNfcPendingIntent, mNdefExchangeFilters, null);
	    } 
 
	    private void disableNdefExchangeMode() { 
	        mNfcAdapter.disableForegroundNdefPush(this);
	        mNfcAdapter.disableForegroundDispatch(this);
	    } 
 
	    private void enableTagWriteMode() { 
	        mWriteMode = true;
	        IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
	        mWriteTagFilters = new IntentFilter[] {
	            tagDetected
	        }; 
4
CodeRank
enableForegroundNdefPush Method Overview
This method was deprecated in API level 14. use setNdefPushMessage(NdefMessage, Activity, Activity...) instead
See Code Examples for other Android NfcAdapter Methods: