ServiceConnector

Service binding for android AIDL services.

License

License

GroupId

GroupId

com.josesamuel
ArtifactId

ArtifactId

serviceconnector
Last Version

Last Version

1.0.6
Release Date

Release Date

Type

Type

aar
Description

Description

ServiceConnector
Service binding for android AIDL services.
Project URL

Project URL

https://github.com/josesamuel/serviceconnector/
Source Code Management

Source Code Management

https://github.com/josesamuel/serviceconnector/

Download serviceconnector

How to add to project

<!-- https://jarcasting.com/artifacts/com.josesamuel/serviceconnector/ -->
<dependency>
    <groupId>com.josesamuel</groupId>
    <artifactId>serviceconnector</artifactId>
    <version>1.0.6</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.josesamuel/serviceconnector/
implementation 'com.josesamuel:serviceconnector:1.0.6'
// https://jarcasting.com/artifacts/com.josesamuel/serviceconnector/
implementation ("com.josesamuel:serviceconnector:1.0.6")
'com.josesamuel:serviceconnector:aar:1.0.6'
<dependency org="com.josesamuel" name="serviceconnector" rev="1.0.6">
  <artifact name="serviceconnector" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.josesamuel', module='serviceconnector', version='1.0.6')
)
libraryDependencies += "com.josesamuel" % "serviceconnector" % "1.0.6"
[com.josesamuel/serviceconnector "1.0.6"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

ServiceConnector

Field and method binding for connecting with Android remote AIDL (or Remoter) services.

Replace the boiler plate service connection codes like -

public class ActivityWithoutServiceConnector extends Activity {

    //remote service interface
    private IEchoService mEchoService;

    /**
     * Service connection that gets call back when service is connected
     */
    private ServiceConnection serviceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName componentName, IBinder service) {
            //get the service 
            mEchoService = IEchoService.Stub.asInterface(service);
        }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {
            mEchoService = null;
        }
    };


    /**
     * Connect with the remote service
     */
    private void conectWithService() {
        Intent serviceIntent = new Intent("util.serviceconnector.ECHO_SERVICE");
        serviceIntent.setComponent(new ComponentName("util.serviceconnector.service", "util.serviceconnector.service.EchoService"));
        startService(serviceIntent);
        bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        conectWithService();
    }

}

Replace that with

public class ActivityWithServiceConnector extends Activity {

    @ServiceInfo(serviceIntent = "util.serviceconnector.ECHO_SERVICE")
    private IEchoService mEchoService;

    @ServiceConnectionCallback
    public void onServiceConnectionChanged(String serviceIntent, boolean connected) throws RemoteException {
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        ServiceConnector.bind(this, this);
    }
}

Getting ServiceConnector

dependencies {
  compile 'com.josesamuel:serviceconnector:1.0.6'
}

Java Doc

ServiceConnector Java Doc

License

Copyright 2018 Joseph Samuel

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0