如何在AIDL中使用ResultReceiver

发布于 2024-10-09 08:38:14 字数 628 浏览 0 评论 0原文

我想使用 ResultReceiver 在 AIDL 中声明异步服务 API,而不是创建自己的回调接口。

但是当我尝试导入 android.os.ResultReceiver 时,它不知道 ResultReceiver 是可打包的。有什么窍门吗?

示例:

import android.os.ResultReceiver;

interface IPrimeService {
    int computePrimes(in int number, in ResultReceiver resultReceiver);
}

结果(Android 2.2):

IPrimeService.aidl:3: couldn't find import for class android.os.ResultReceiver

似乎如果我在项目中的 src/android/os 中创建 ResultReceiver.aidl ,就像:

package android.os;

parcelable ResultReceiver;

它可以工作,但这看起来像是一个黑客。有更好的办法吗?

谢谢,埃里克

I'd like to declare an asynchronous service API in AIDL using ResultReceiver instead of creating my own callback interface.

But when I try to import android.os.ResultReceiver, it doesn't know that ResultReceiver is parcelable. Is there a trick?

Example:

import android.os.ResultReceiver;

interface IPrimeService {
    int computePrimes(in int number, in ResultReceiver resultReceiver);
}

Results in (Android 2.2):

IPrimeService.aidl:3: couldn't find import for class android.os.ResultReceiver

It seems if I create ResultReceiver.aidl in src/android/os within my project like:

package android.os;

parcelable ResultReceiver;

it works, but that seems like such a hack. Is there a better way?

Thanks, Eric

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飞烟轻若梦 2024-10-16 08:38:14

我遇到了类似的问题..我编辑了 /platform/android-<#>/framework.aidl 以包含

parceable android.os.ResultReceiver;

行然后它就可以工作了

http://amdroid.ampache.org/?p=38

I ran into a similar issue.. I edited /platform/android-<#>/framework.aidl to include the line

parceable android.os.ResultReceiver;

and then it works

credit: http://amdroid.ampache.org/?p=38

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文