NfcAdapter enableForegroundDispatch - 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 enableForegroundDispatch method.

This code example shows how to use the following methods:enableForegroundDispatch
    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())) {
            Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
            if (NFCProfileUtils.writeTag(NFCProfileUtils.getProfileAsNdef(mProfile), detectedTag)) {
                Toast.makeText(this, R.string.profile_write_success, Toast.LENGTH_LONG).show();
                NFCProfileUtils.vibrate(this);
            } else { 
                Toast.makeText(this, R.string.profile_write_failed, Toast.LENGTH_LONG).show();
            } 
            finish();
6
CodeRank
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
This code example shows how to use the following methods:enableForegroundDispatch
                .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|
                          Intent.FLAG_ACTIVITY_CLEAR_TOP);
      PendingIntent pi=PendingIntent.getActivity(this, 0, i, 0);
       
      inWriteMode=true;
      nfc.enableForegroundDispatch(this, pi, tagFilters, null);
    } 
  } 
   
  @Override 
  public void onPause() { 
    if (isFinishing()) {
      nfc.disableForegroundDispatch(this);
      inWriteMode=false;
    } 
     
    super.onPause(); 
  } 
   
  private byte[] buildUrlBytes(String url) {
6
CodeRank
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
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
This code example shows how to use the following methods:enableForegroundDispatch
    } 
 
    @Override 
    protected void onResume() { 
        super.onResume(); 
        mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
    } 
 
    @Override 
    protected void onPause() { 
        super.onPause(); 
        mNfcAdapter.disableForegroundDispatch(this);
    } 
 
    @Override 
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
 
        NdefMessage[] messages = getNdefMessages(intent);
        boolean isMatch = messages != null
6
CodeRank
This code example shows how to use the following methods:enableForegroundDispatch
    } 
 
    @Override 
    public void onResume() { 
        super.onResume(); 
        if (mAdapter != null) mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters,
                mTechLists);
    } 
 
    @Override 
    public void onNewIntent(Intent intent) {
        Log.i("Foreground dispatch", "Discovered tag with intent: " + intent);
        mText.setText("Discovered tag " + ++mCount + " with intent: " + intent);
    } 
 
    @Override 
    public void onPause() { 
        super.onPause(); 
        if (mAdapter != null) mAdapter.disableForegroundDispatch(this);
    } 
6
CodeRank
This code example shows how to use the following methods:enableForegroundDispatch, setNdefPushMessage
     * 
     * If this needs to be changed in the future, change what the message is, or list a different activity in 
     * setNdefPushMessage. 
     */ 
    public void enableNdefExchangeMode() { 
        adapter.setNdefPushMessage(message, activity);
        adapter.enableForegroundDispatch(activity, nfcPendingIntent, ndefExchangeFilters, null);
    } 
 
    /** 
     * Call to disable any sort of exchange between NDEF devices. 
     */ 
    public void disableNdefExchangeMode() { 
//        passing a null value disables foreground NDEF push in the specified activity. 
        adapter.setNdefPushMessage(null, activity);
        adapter.disableForegroundDispatch(activity);
    } 
 
    /** 
     * Gets the message from a text view and turns it into an NDEF Message and returns it as well as setting the message 
6
CodeRank
This code example shows how to use the following methods:enableForegroundDispatch, isEnabled
     * @param targetActivity The Activity that is in foreground and wants to 
     * have NFC Intents. 
     * @see #disableNfcForegroundDispatch(Activity) 
     */ 
    public static void enableNfcForegroundDispatch(Activity targetActivity) {
        if (mNfcAdapter != null && mNfcAdapter.isEnabled()) {
 
            Intent intent = new Intent(targetActivity,
                    targetActivity.getClass()).addFlags(
                            Intent.FLAG_ACTIVITY_SINGLE_TOP);
            PendingIntent pendingIntent = PendingIntent.getActivity(
                    targetActivity, 0, intent, 0);
            mNfcAdapter.enableForegroundDispatch(
                    targetActivity, pendingIntent, null, new String[][] {
                            new String[] { MifareClassic.class.getName() } });
        } 
    } 
 
    /** 
     * Disable the NFC foreground dispatch system for the given Activity. 
5
CodeRank
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

Related NfcAdapter enableForegroundDispatch Questions & Answers:

enableForegroundDispatch Method Overview
Enable foreground dispatch to the given Activity.
See Code Examples for other Android NfcAdapter Methods: