private void mockService(IInAppBillingService service){
IBinder iBinder = Mockito.mock(IBinder.class);
Mockito.when(iBinder.queryLocalInterface(Mockito.anyString())).
thenReturn(service);
Shadows.shadowOf(RuntimeEnvironment.application).setComponentNameAndServiceForBindService(
new ComponentName("com.android.vending.billing", "IInAppBillingService"), iBinder);
}
这是我的测试代码。我很困惑组件名称应该是什么。
这是我在代码中连接服务的方式:
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
List<ResolveInfo> intentServices = context.getPackageManager().
queryIntentServices(serviceIntent, 0);
if (intentServices != null && !intentServices.isEmpty()) {
// service available to handle that Intent
context.bindService(serviceIntent, this, Context.BIND_AUTO_CREATE);
} else {
// no service available to handle that Intent
onNoServiceAvailable(failureMethodName);
}