-
-
Notifications
You must be signed in to change notification settings - Fork 13
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'
}
The minimum steps required to start using the extractor service are:
- 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) { }
};
- 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
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
}
}
});
- (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 |
- 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
}
};
- 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);