У меня есть GpsService в пакете (packageShared), и мне нужно получить к нему доступ из другого пакета (packageClient). Я получаю "getService () не является общедоступным в packageShared.GpsService.Localbinder '. Доступ из внешнего пакета невозможен." в следующей строке mService = (GpsService) binder.getService (); в Android Studio.
У меня есть другой класс внутри пакета. Отлично работает, используя тот же код.
Вот код на упаковке клиента:
// Monitors the state of the connection to the service.
private final ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
GpsService.LocalBinder binder = (GpsService.LocalBinder) service;
mService = (GpsService) binder.getService();
mBound = true;
}
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
mBound = false;
}
};
Вот код на упаковке Shared:
public class GpsService extends Service {
public GpsService() {
}
other methods here...
/**
* Class used for the client Binder. Since this service runs in the same process as its
* clients, we don't need to deal with IPC.
*/
public class LocalBinder extends Binder {
GpsService getService() {
return GpsService.this;
}
}
}
Заранее спасибо.