Issue
I'm trying to test an external binding to a Service I've defined. Following the class I'm using for instrumented test:
@Rule
public final ServiceTestRule serviceRule = new ServiceTestRule();
@Test
public void testWithBoundService() throws TimeoutException, RemoteException {
IMyInterface iMyInterface;
Intent serviceIntent =
new Intent(ApplicationProvider.getApplicationContext(),
MyService.class);
IBinder binder = serviceRule.bindService(serviceIntent);
assertNotNull(binder);
iMyInterface = IMyInterface.Stub.asInterface(binder);
assertTrue(iMyInterface.retrieveValue(new Attribute()).getValues().get(0).equals("home"));
}
@Test
public void testWithBoundServiceExternal() throws TimeoutException, RemoteException {
IMyInterface iMyInterface;
Intent serviceIntent = new Intent();
serviceIntent.setClassName("a.b.c.d", "a.b.c.d.MyService");
IBinder binder = serviceRule.bindService(serviceIntent);
assertNotNull(binder);
iMyInterface = IMyInterface.Stub.asInterface(binder);
boolean reachedHere = false;
assertTrue(iMyInterface.retrieveValue(new Attribute()).getValues().get(0).equals("home"));
}
First Test function runs without any errors, the second fails with the following message:
Failed to bind to service! Is your service declared in the manifest?
The Service is defined in the package a.b.c.d, the same of the Aidl interface, while the instrumentedTest is running in the a.b.c.e package
Solution
Few minutes later I realized that the Manifest had a different package, and, in order to call the Service you should use the package of the Manifest. So suppose that you hava, in the tag an attribute package="a.b.c.f", in order to call an external service you should use:
serviceIntent.setClassName("a.b.c.f", "a.b.c.d.MyService")
Answered By - Antonio La Marra
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.