2

For an engineering project I need to basically trick my phone to come out of NFC searching mode and into a mode where the phone is continuously putting out energy. Obviously I have activated NFC in the settings, but the only way I can trick it into leaving the searching mode and have it put out energy continuously is if I leave it on top of a blank tag.

I was thinking of implementing this NFC beam function: public boolean invokeBeam (Activity activity) and implanting it into the BeamLargeFiles sample code provided in Android studio, posted below.

I'm new to app development (though I have a fair bit of coding experience) so I'm just not sure if it's feasible, or if I'm looking in the right places. Any thoughts, ideas and help is appreciated!

package com.example.android.beamlargefiles;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.text.Html;
import android.widget.TextView;
import android.view.Menu;

import com.example.android.common.activities.SampleActivityBase;
import com.example.android.common.logger.Log;
import com.example.android.common.logger.LogFragment;
import com.example.android.common.logger.LogWrapper;
import com.example.android.common.logger.MessageOnlyLogFilter;

/**
 * A simple launcher activity containing a summary sample description
 * and a few action bar buttons.
 */
public class MainActivity extends SampleActivityBase {

    public static final String TAG = "MainActivity";

    public static final String FRAGTAG = "BeamLargeFilesFragment";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView sampleOutput = (TextView) findViewById(R.id.sample_output);
        sampleOutput.setText(Html.fromHtml(getString(R.string.intro_message)));

        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        BeamLargeFilesFragment fragment = new BeamLargeFilesFragment();
        transaction.add(fragment, FRAGTAG);
        transaction.commit();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    /** Create a chain of targets that will receive log data */
    @Override
    public void initializeLogging() {
        // Wraps Android's native log framework.
        LogWrapper logWrapper = new LogWrapper();
        // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
        Log.setLogNode(logWrapper);

        // Filter strips out everything except the message text.
        MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter();
        logWrapper.setNext(msgFilter);

        // On screen logging via a fragment with a TextView.
        LogFragment logFragment = (LogFragment) getSupportFragmentManager()
                .findFragmentById(R.id.log_fragment);
        msgFilter.setNext(logFragment.getLogView());
        logFragment.getLogView().setTextAppearance(this, R.style.Log);
        logFragment.getLogView().setBackgroundColor(Color.WHITE);

        Log.i(TAG, "Ready");
    }
}

From the beamlargedata sample code provided by android studio

basgys
  • 4,320
  • 28
  • 39
Marko
  • 21
  • 1

1 Answers1

1

When no suitable NFC device is in range the NFC controller will constantly search all technologies for a tag or peer-to-peer device. It does this by sending out short bursts separated by no field activity (to save power).

If you have a newer device it is also very likely that the NFC Controller will only generate a very weak RF field to save power. This field is not strong enough to power a NFC tag but is strong enough for the chip to detect if there is something resonating at 13.56Mhz.

With standard Android you cannot change this behaviour. There is no programatical way in the API to enable the mode you're looking for.

However, if you can stretch your requirements a bit you can likely get something close to what you want.

Option 1:

Enable the Reader-Mode. Call enableReaderMode using the EXTRA_READER_PRESENCE_CHECK_DELAY extra. Set this to the a very high value.

Now, if a tag enters the RF field the NFC controller won't check for presence that often anymore. You can activate your RF field by touching a tag, then removing it.

The RF field will be stable until the presence check delay expires.

Option 2:

If rooting the device is an option, you can hack yourself into the low level NFC stack. Each NFC controller that I've worked with so far has one or more test modes for antenna calibration. Just outputting an RF field is one of the very common test modes.

Reading the source-code of the nfc-stack will likely show you how to enable such a mode. That takes some digging in the source-code and is not for the faint heart, but it is doable.

Nils Pipenbrinck
  • 83,631
  • 31
  • 151
  • 221
  • Nils, thanks for the quick reply, so you don't know of any way to skip the step where it is searching for a tag and go directly to the stage where it sees a blank tag? If not, using either NXP's Taginfo app or the NFC Spy app, it seems to have a faster searching pattern than apps on the market (tested visually with an LED NFC detector), any ideas on how they implemented this? I'd like to try and cut down on the time between searching probes next if there's no way to directly tell the phone to output energy. – Marko Oct 26 '15 at 06:40
  • @Marko there is no way, and I doubt that Taginfo can modify the search pattern because there is no API for that. – Nils Pipenbrinck Oct 26 '15 at 13:58