I want to pass a Listener through a System Service in Android. I created my Listener Interface using AIDL.

Content of IStatusBarLostFocusCallback.aidl:

package com.android.internal.statusbar;

interface IStatusBarLostFocusCallback {
  void onLostFocus();
}

then I extended Androids IStatusBarService.aidl with following Function:

void setStatusBarLostFocusCallback(in IStatusBarLostFocusCallback listener);

and also imported my Interface (in the same directory)

import com.android.internal.statusbar.IStatusBarLostFocusCallback;

In Androids StatusBarManagerService, I extended this Interface since I read to do this in this Thread: Android remote service callbacks like this:

public interface StatusBarLostFocusCallback extends IStatusBarLostFocusCallback {
    public void onLostFocus();
}

Now I want to set the Listener with the setStatusBarLostFocusCallback which is defined in IStatusBarService.aidl and implemented in StatusBarManagerService.java.

However, when I try to compile the Framework, I get the following Error

out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/com/android/internal/statusbar/IStatusBarService.java:287: cannot find symbol
symbol  : class IStatusBarLostFocusCallback
location: package com.android.internal.statusbar
com.android.internal.statusbar.IStatusBarLostFocusCallback _arg0;

What have I missed. Do I have to write a .java for the IStatusBarLostFocusCallback? If so, what should be in there?

有帮助吗?

解决方案 2

I managed it now. I forgot to add my AIDL to the Build in /frameworks/base/Android.mk (I did forget to mention I am building the Source). I now no longer extend the Interface but implement it like this:

mBarService.setStatusBarLostFocusCallback(new IStatusBarLostFocusCallback.Stub(){
    public void onLostFocus(){
        mHasStatusbarFocus = false;
    }
});

其他提示

you try as described like this ?

If yes, and this didn't work, you may implement methods from aidl like this, for example:

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

Class aClass = Class.forName(telephonyManager.getClass().getName());

Method method = aClass.getDeclaredMethod("getITelephony");
method.setAccessible(true);

ITelephony telephonyService = (ITelephony) method.invoke(telephonyManager);
telephonyService.endCall();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top