Android - 是否可以在远程服务的上下文中调用未公开的公共方法

时间:2013-05-31 16:39:46

标签: android service aidl

我有一个远程服务,一个远程服务接口和一个绑定到它的客户端。我想知道是否有可能在服务中调用方法(例如UnexposedMethod2),这些方法没有在服务上下文的接口中公开。

我的代码如下:

SomeService.java:

public class SomeService extends IntentService {
    private IRemote.Stub iremote_sub = new IRemote.Stub(){
        public String SomeMethod(String key) throws RemoteException {
            return SomeService.this.UnexposedMethod1(key);
        }
    };

    private String UnexposedMethod1(String key){
        /* Do Something With key */
        ........................

        return UnexposedMethod2();
    }

    public String UnexposedMethod2(){
        String str = new String();

        /* Do Something With str and Fetch Data from Providers */
        return str;
    }

}

IRemote.aidl:

interface IRemote{
    String SomeMethod(String key)
}

SomeActivity.java:

public class SomeActivity extends Activity {
    private ServiceConnection myConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {

            myService = IGetContactsString.Stub.asInterface(service);

    /* Can I call UnexposedMethod2 here on service's context? */
        }

        public void onServiceDisconnected(ComponentName className) {
            myService = null;
        }
    };  
}

任何建议都有帮助。非常感谢!

0 个答案:

没有答案