工信部网站备案查询系统,找项目,wordpress中文版去广告,建网站吧1、build中版本号为30及以上时#xff0c;aidl无效#xff0c;解决方案
①在客户端的manifest.xml中添加一下代码#xff0c;其中代码中的包名为服务端的包名
manifest
...
application
..../application
queries package android:na…1、build中版本号为30及以上时aidl无效解决方案
①在客户端的manifest.xml中添加一下代码其中代码中的包名为服务端的包名
manifest
...
application
..../application
queries package android:namecom.example.clientapplication/intentaction android:nameandroid.intent.action.MService//intent
/queries
/manifest②修改build中的版本号 2、打开aidl中服务端的服务service出现闪退的问题
Caused by:
java.lang.RuntimeException: Didnt create service XXX on path:
DexPathList[[zip file /data/app/com.chemao.certification-2/base.apk],
nativeLibraryDirectories[/data/app/com.chemao.certification-2/lib/arm, /vendor/lib, /system/lib]]
方法service的位置放错了service应该放在java目录下。
aidl中服务端的目录结果如下所示 3、跨进程通信aidl最简单的方法
①服务端
1AS切换模式为project对main右键创建aidl文件如下图 2在创建的文件中定义想实现的接口 3build projection
如果rebuild出现问题的话可以先clean projection 4创建类继承service在service中创建内部类实现aidl中定义的接口数据在java目录下创建不要在aidl中进行创建不然后续会出现问题。 public class MService extends Service {private IAidlInterface mBinder;NullableOverridepublic IBinder onBind(Intent intent) {Log.d(TAG, onBind: intent);return mBinder.asBinder();}Overridepublic void onCreate() {super.onCreate();Log.d(TAG, onCreate: );mBinder new Binder();}private class Binder extends IAidlInterface.Stub{private static final String TAG mBinder;Overridepublic void basicTypes() throws RemoteException {Log.d(TAG, basicTypes: 我是服务端数据信息);}}
}5在manifest中定义service不然service无作用在定义service中可以声明action进行隐式调用 到此为止服务端的工作完成
②客户端
1在manifest中进行安全防护 ②将服务端中aidl复制过来和服务端一模一样进行rebuild即可。 3在activity中进行服务的绑定bindservice返回值为trueonServiceConnected中有打印就知道服务成功。
public class MainActivity extends AppCompatActivity {private IAidlInterface mIExtraAidlInterface;private ServiceConnection mServiceConn;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button findViewById(R.id.name);// bindService();mServiceConn new ServiceConnection() {Overridepublic void onServiceConnected(ComponentName name, IBinder service) {mIExtraAidlInterface IAidlInterface.Stub.asInterface(service);try {mIExtraAidlInterface.basicTypes();} catch (RemoteException e) {throw new RuntimeException(e);}Log.d(TAG, onServiceConnected: );}Overridepublic void onServiceDisconnected(ComponentName name) {// mIExtraAidlInterface null;Toast.makeText(MainActivity.this, 0000, Toast.LENGTH_SHORT).show();Log.d(TAG, onServiceDisconnected: );}};bindService();}private void bindService(){Intent intent new Intent();intent.setAction(android.intent.action.MService);intent.setPackage(com.example.clientapplication);ResolveInfo resolveInfo getPackageManager().resolveService(intent, 0);Log.d(TAG, bindService: resolveInfo);bindService(intent, mServiceConn, BIND_AUTO_CREATE);Log.d(TAG, mServiceConn: mServiceConn);}Overridepublic boolean bindService(Intent service, ServiceConnection conn, int flags) {Log.d(TAG, bindService: service service conn conn flags flags);Log.d(TAG, bindService: super.bindService(service,conn,flags));return super.bindService(service, conn, flags);}Overrideprotected void onDestroy() {super.onDestroy();unbindService(mServiceConn);}
}对于aidl的具体说明及复杂类型或者回调数据的使用可见https://developer.android.google.cn/guide/components/aidl?hlzh_cn