SCMHelper

public class SCMHelper

The SCMHelper class manages several software components throughout the application activities lifecycle.

This class should be used to enable NFC reader on activity resume or to save cache on activity pause for instance. SCMHelper can be used in two different ways:

These two ways to use SCMHelper are equivalent, choice is up to the developer. Sample codes are given below.

Using an Activity activity:

public class MyActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SCMHelper.activityCreated(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        SCMHelper.activityDestroyed(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        SCMHelper.activityResumed(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        SCMHelper.activityPaused(this);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        SCMHelper.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        SCMHelper.activityNewIntent(intent);
    }
}

Using an AppCompatActivity activity:

public class MyActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SCMHelper.observableActivityCreated(this);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        SCMHelper.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        SCMHelper.activityNewIntent(intent);
    }
}

Methods

activityCreated

public static void activityCreated(Activity activity)

Initializes SCM backend and checks on user permissions. Starts listening to USB reader events and loads cache.

This method must be called in Main Thread.

Parameters:
  • activity – activity in which this method must be called, in Activity::onCreate.

activityDestroyed

public static void activityDestroyed(Activity activity)

Stops listening to USB reader events.

Parameters:
  • activity – activity in which this method must be called, in Activity::onDestroy.

activityNewIntent

public static void activityNewIntent(Intent intent)

Looks for NFC TAG in activity intent.

Parameters:
  • intent – the intent received by the activity.

activityPaused

public static void activityPaused(Activity activity)

Stops listening to BLE and NFC reader events, and saves cache.

Parameters:
  • activity – activity in which this method must be called, in Activity::onPause.

activityResumed

public static void activityResumed(Activity activity)

Starts listening to BLE and NFC reader events.

Parameters:
  • activity – activity in which this method must be called, in Activity::onResume.

observableActivityCreated

public static void observableActivityCreated(AppCompatActivity activity)

Starts to observe given activity lifecycle and initializes SCM backend.

This method must be called in Main Thread.

SCMHelper.activityCreated, SCMHelper.activityDestroyed, SCMHelper.activityResumed and SCMHelper.activityPaused are automatically called.

Parameters:
  • activity – activity to observe.

observableActivityDestroyed

public static void observableActivityDestroyed(AppCompatActivity activity)

Stops to observe given activity lifecycle.

SCMHelper.observableActivityCreated is assumed to be previously called with same activity. This method is automatically called in given activity onDestroy method.

Parameters:
  • activity – activity to stop to observe.

onRequestPermissionsResult

public static void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)

Transmits request permissions result to the middleware.

Parameters:
  • requestCode – the request code given by Activity.onRequestPermissionsResult(int,String[],int[]) callback.
  • permissions – the permissions given by Activity.onRequestPermissionsResult(int,String[],int[]) callback.
  • grantResults – the grantResults given by Activity.onRequestPermissionsResult(int,String[],int[]) callback.