Basically I want to implement a service that exposes his interface to be used via Android IPC in other apps. The client application should then be able to register a Messenger to receive messages from the service. Since Messenger is Parcelable I thought it should be as simple as:
package com.example;
import android.os.Messenger;
interface MyRemoteService 开发者_开发知识库{
void registerMessenger(in Messenger messenger);
}
However, I get the error couldn't find import for class android.os.Messenger
I asked Google and found a blog post from 2010 in which the problem was solved by modifying the platform/android-<#>/framework.aidl
inside the android sdk so every developer has to modify that file on his/her local machine, which is not a viable solution for me.
Can I register the Messenger in another way that is supported in the Android 7 API (2.1)?
It seems to work using the following method:
Create Messenger.aidl
with the following contents in package android.os
:
package android.os;
parcelable Messenger;
Create your own aidl file like this:
package com.example.name;
import android.os.Messenger;
interface IRemoteService {
void registerMessenger(in Messenger messenger);
}
Create a file titled Messenger.aidl in your project:
package com.your.package.here;
parcelable android.os.Messenger;
精彩评论