AIDL interface between two applications

I came across a common wall with an AIDL interface. I have an application that should be controlled through a third-party application (I have enough control over this, so I can ask them to implement what I need in their activities)

Initially, my application was also active with an interface and everything, but I changed it as a background service and for testing, I created a dummy application that manages to run a service application in the background.

Now I need a way to request method calls from a service (basically start, stop, sendData). I created .aidl files for both applications. The helpl file implements only one method (here some other question is given).

package foo.testapp;
interface IScript 
{
     String executeScript(String script); 
}

while other help is the same except for the package "foo.otherapp". The implementations I found on the Internet have the same package for both helper files, but this causes an error for me (suppose this is only a problem on my part, as I hate namespaces and packages, so I often call them bad if it important for change them i can do this)

The plan was to use this method to send a string to the service and just have a switch over the predefined strings to call the correct method (three different methods can also be implemented if this improves usage).

In any case ... I can’t get help to connect, I get the error "Unable to start service intent

{act = foo.testapp.IScript}: not found

, , .. packagenames )

activity

private final IScript.Stub mBinder = new IScript.Stub()
{
    @Override
    public String executeScript(String script) throws RemoteException
    {
        // TODO Auto-generated method stub
    }
};
IScript mService = null;
private ServiceConnection mConnection = new ServiceConnection() 
{
     public void onServiceConnected(ComponentName className, IBinder service) 
     {
         mService = IScript.Stub.asInterface(service);
     }
     public void onServiceDisconnected(ComponentName className) 
     {
         mService = null;
     }
 };

OnCreate() :

bindService(new Intent(IScript.class.getName()),
            mConnection, Context.BIND_AUTO_CREATE);

:

@Override
public IBinder onBind(Intent intent) 
{
    // Select the interface to return.  If your service only implements
    // a single interface, you can just return it here without checking
    // the Intent.
    if (IScript.class.getName().equals(intent.getAction())) 
    {
        return mBinder;
    }
    return null;
}

/**
 * The IRemoteInterface is defined through IDL
 */
private final IScript.Stub mBinder = new IScript.Stub() 
{
    @Override
    public String executeScript(String script) throws RemoteException 
    {
        if (script == "test")
        {
            return "foo";
        }
        return "fail";
    }
};

, , ;

, , , - . :

    <intent-filter>
        <action android:name="foo.otherapp.IScript" />
    </intent-filter>

    <intent-filter>
        <action android:name="foo.testapp.IScript" />
    </intent-filter>

, . . , .

, .

!

+3
2

, .

Android

( , )

, serviceimpl . " ", ( ).

, .

": Android SDK 1.5.

+3

. , RemoteInterface.aidl , - , !?

Eclipse, ( ). / , " " . ( , ) ​​ . , , .

interface.aidl , .

Ant , , ant_rules.xml aidl, build.xml, .

, 17 " " :

+1

Source: https://habr.com/ru/post/1784699/


All Articles