1

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)?

n_l
  • 844
  • 1
  • 6
  • 19

2 Answers2

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);
}
  • Interesting that this is still an issue two years after the original post. However your answer is exactly what I was referring to in [my comment](http://stackoverflow.com/questions/6858531/how-to-use-messenger-as-argument-in-android-ipc/19095632?noredirect=1#comment8158408_6859471) to the original answer. – n_l Oct 01 '13 at 17:39
  • Your answer was not entirely clear to me, so I thought I'd write it again more clearly. –  Oct 02 '13 at 18:16
1

Create a file titled Messenger.aidl in your project:

package com.your.package.here;

parcelable android.os.Messenger;
Austin Hanson
  • 21,820
  • 6
  • 35
  • 41
  • That almost worked. But taking your advice I created a file Messenger.aidl in src/android/os with the line "parcelable Messenger;" in it. That seems to work, but is that style ok? – n_l Jul 28 '11 at 13:33