Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

First we recommend to implement the LoaderCallback interface in order to receive the "onLoaded" event. This call is triggered as soon as the cgJCE finished loading. Loading itsself happens asynchrously i.e. the loader starts the loading process and returns immediately in fact it is not completely but almost immediately since we have to preload a legacy provider in order to guarantee compatibilityness to programs using older versions of our JCE.. When the job has finished "onLoaded" is called when the callback is implemented and given as parameter on "load" call.
We also recommend checking whether the cgJCE is installed by isProviderInstalled. Also check if the providers are already loaded by isProviderAvailable before calling the load function.
An example could look like this:

Code Block
languagejava
linenumberstrue
collapsetrue
public class LoaderSample implements LoaderCallback

...


{

...


Context _c;

...

 
public LoaderSample(Context c)

...


{

...


this._c = c;

...


}

...

 
@Override

...


public void onLoaded()

...

 
{

...


//loading the JCE has finished

...

 
//get provider

...


Provider p = Security.getProvider("CERTGATE");

...

 
//do something with the

...

 provider
...
} 
public void startLoading() throws ProviderLoadingFailedException, ProviderSignatureInvalidException, ProviderNotFoundException

...


{

...


if (ProviderLoader.isProviderInstalled(this._c))

...


{

...


if (!ProviderLoader.isProviderAvailable())

...


{

...


ProviderLoader.load(this._c, this);

...


}

...


else

...


{

...


//already loaded!

...


}

...


}

...


else

...


{

...


//not installed!

...


}

...


}

...


}

Automated loading via JCEInitTask

For easier integration we implemented the JCEInitTask which extends from Android's AsyncTask and loads the cgJCE with more detailed success / failure information.
It is recommended to implement the OnTaskFinishCallback since it gives information about how the loading resulted.
Furthermore loading the cgJCE by this task gives the opportunity to fade-in a progress- or a custom dialog which dissapears after the loading has finished. This makes sense when the user shall be blocked or notified as long as the cgJCE is loading. The usage of this dialog is optional. When null is used as parameter a default progress dialog is shown to the user otherwise the custom dialog appears. There is also a constructor for not using any dialog.
Additionally there is the option to show message toasts when loading starts and finishes.
The following example shows how to use the JCEInitTask.
public class LoaderSample implements OnTaskFinishedCallback
{
Context _c;
public LoaderSample(Context c)
{
this._c = c;
}
public void startLoading()
{
new InitJCETask(this._c, null, this, false).execute();
}
@Override
public void onFinished(JCELoadResult result)
{
switch (result)
{
case _E_ALREADY_LOADED{_}:
break;
case _E_NOT_INSTALLED{_}:
break;
case _E_SUCCESS{_}:
//get providers
ProviderLoader.getProviders();
break;
case _E_UNSPECIFIED_ERROR{_}:
break;
}
}
}

Anchor
_Toc456191102
_Toc456191102
Features

...