{"id":19340415,"url":"https://github.com/tim9liu9/aidlclient-aidlserver","last_synced_at":"2026-05-18T05:02:47.881Z","repository":{"id":21468690,"uuid":"24787201","full_name":"Tim9Liu9/AIDLClient-AIDLServer","owner":"Tim9Liu9","description":null,"archived":false,"fork":false,"pushed_at":"2014-10-04T11:06:40.000Z","size":168,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-06T11:37:46.836Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tim9Liu9.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-04T10:48:17.000Z","updated_at":"2017-03-04T16:16:59.000Z","dependencies_parsed_at":"2022-08-21T15:01:00.141Z","dependency_job_id":null,"html_url":"https://github.com/Tim9Liu9/AIDLClient-AIDLServer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim9Liu9%2FAIDLClient-AIDLServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim9Liu9%2FAIDLClient-AIDLServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim9Liu9%2FAIDLClient-AIDLServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim9Liu9%2FAIDLClient-AIDLServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tim9Liu9","download_url":"https://codeload.github.com/Tim9Liu9/AIDLClient-AIDLServer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240443483,"owners_count":19802061,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T03:26:24.316Z","updated_at":"2026-05-18T05:02:47.815Z","avatar_url":"https://github.com/Tim9Liu9.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"AIDLClient-AIDLServer\n=====================\n\n\n教程说明见这里 http://www.linuxidc.com/Linux/2012-06/63205.htm\n\n\n\nAndroid aidl实现两个apk之间远程调用Service:\n=======================1=========================\nAidl，Android平台的IPC方式之一，基于系统的Ibinder机制。\n\n网上大多数例子都是在一个apk下来测试调用service，现在我在两个project下面来调用。\n\n一个是server project，一个是client project\n\n首先我们建立的是server project，这里面要实现aidl文件和一个service，activity只是用来启动service的，当然，你也可以通过发广播的形式来启动service。\n\n首先看IAidlService.aidl文件：\n\n    package com.ds.server;   \n    interface IAidlService {     \n        int getType();    \n    }    \n\n这样在eclipse里面自动编译的时候会在gen下面生成IAidlService.java文件（灯下我们的client project要用）。\n然后新建一个service，这个service里面has a IAidlService的stub对象，service具体代码如下：\n\n=======================2=========================\n这里一定要实现onBind方法，并返回一个IAidlService.Stub对象。\n再去AndroidManifest.xml注册这个service:\n\n    \u003cservice  \n                android:name=\".AidlService\"  \n                android:enabled=\"true\"  \n                android:process=\":remote\" \u003e  \n                \u003cintent-filter\u003e  \n                    \u003caction android:name=\"com.ds.server.IAidlService\" /\u003e  \n                    \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e  \n                \u003c/intent-filter\u003e  \n            \u003c/service\u003e  \n\nandroid:enabled=\"true\"\n\nandroid:process=\":remote\"这两个标签可有可无。\n\n只要注册了这个service就行。\n\n好了，到此，服务端已经完成。 \n\n=======================3=========================\n下面我们开始client project。\n\nclient project比较简单，需要注意的地方是，首先需要把server project中gen文件夹中aidl生成的那个IAidlService.java类以及包都拷贝到我们的client project中。\n\n（注意：client project的包名为com.ds.client;另外一个包名com.ds.server以及这个server包下面的IAidlService.java类都是从server project的gen文件夹拷贝过来的，至于gen文件夹的其他文件就不需要拷贝过来\n\n注意几点：\n\n1，import com.ds.server.IAidlService;使用的是我们拷贝过来的IAidlService.java类\n\n2，需要一个ServiceConnection对象\n\n3，通过Intent service = new Intent(IAidlService.class.getName());\n\nbindService(service, connection, BIND_AUTO_CREATE);来bind service。这样就可以调用aidl中定义的接口来获取service中的值了。\n\n唉，由于在使用中没有注意拷贝server project中gen文件夹下面的包和IAidlService.java，老是出现Unable to start service Intent这样的错误。搞了好久。\n\n注意使用的时候，先要运行server project，启动服务，然后再运行client project。 \n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftim9liu9%2Faidlclient-aidlserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftim9liu9%2Faidlclient-aidlserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftim9liu9%2Faidlclient-aidlserver/lists"}