...
Code Block |
---|
language | java |
---|
theme | Confluence |
---|
title | LoaderSample |
---|
linenumbers | true |
---|
collapse | truemanual LoaderSample |
---|
|
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!
}
}
}
|
...
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.
Code Block |
---|
language | java |
---|
title | LCEInitTask LoaderSample |
---|
|
public class LoaderSample implements OnTaskFinishedCallback |
...
...
...
public LoaderSample(Context c) |
...
...
}
public void startLoading() |
...
{
new InitJCETask(this._c, null, this, false).execute(); |
...
}
@Override
public void onFinished(JCELoadResult result) |
...
...
{
case _E_ALREADY_LOADED{_}: |
...
...
case _E_NOT_INSTALLED{_}: |
...
...
...
...
providers
ProviderLoader.getProviders(); |
...
...
case _E_UNSPECIFIED_ERROR{_}: |
...
...
Anchor |
---|
| _Toc456191102 |
---|
| _Toc456191102 |
---|
|
Features
...