Skip to content

Using the service

Alan Woolley edited this page Feb 13, 2018 · 3 revisions

The service can be integrated in to your own application by adding the following dependency to your gradle build script:

repositories {
    jcenter()
}

dependencies {
    implementation 'uk.co.armedpineapple.innoextract:service:1.1.1'
}

Usage

The minimum steps required to start using the extractor service are:

  1. Create a connection callback for the service binding
private ServiceConnection mConnection = new ServiceConnection() {

    @Override public void onServiceConnected(ComponentName componentName,
            IBinder iBinder) {

        ExtractService.ServiceBinder binder = (ExtractService.ServiceBinder) iBinder;
        ExtractService service = binder.getService();
        // Use the ExtractService object to interact with the service
    }

    @Override public void onServiceDisconnected(ComponentName componentName) { }
};
  1. Bind to the service in your Activity's onStart method, and unbind in your Activity's onStop method
@Override
protected void onStart() {
    super.onStart();
    Intent intent = new Intent(this, ExtractService.class);
    bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}

@Override
protected void onStop() {
     super.onStop();
     unbindService(mConnection);
}

For a more complete guide for working with Android services, see the Android Developer Guide

Examples

Check if a file is a valid Inno Setup file

File fileToExtract = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "myfile.exe");
service.check(fileToExtract, new CheckCallback() {
    @Override public void onResult(boolean valid) {
        if (valid) {
            // File is a valid Inno Setup File
        } else {
            // file is invalid
        }
    }
});

Extracting an Inno Setup file

  1. (Optional) Create a configuration.
Configuration config = new Configuration();
config.setShowFinalNotification(false);
config.setShowLogActionButton(false);
config.setShowOngoingNotification(true);

If no configuration is provided or the options are unset, then the default configuration is used:

Option Default Value
show final notification true
show log action button true
show ongoing notification true
  1. Define a callback
ExtractCallback callback = new ExtractCallback() {
    @Override public void onProgress(int value, int max, int speedBps, int remainingSeconds) {
        // Called after every chunk extracted
    }

    @Override public void onSuccess() {
        // Called when extract is successful

    }

    @Override public void onFailure(Exception e) {
        // Called when extract fails. See exception for reason
    }
};
  1. Call the service's extract method
File fileToExtract = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "myfile.exe");
File extractTo = Environment.getExternalStorageDirectory();
service.extract(fileToExtract, extractTo, callback, config);