无法从Android Q中的“ android.location.ILocationManager”中找到方法reportLocation()

问题描述 投票:0回答:1

我正在尝试通过“ android.location.ILocationManager $ Stub”的反射获取方法reportLocation()。

CODE:

Class mStub = Class.forName(“ android.location.ILocationManager $ Stub”);方法getInterface = mStub.getMethod(“ asInterface”,IBinder.class);

Class mServiceManager = Class.forName(“ android.os.ServiceManager”);方法getService = mServiceManager.getMethod(“ getService”,String.class);

Object iBindermInterface = getService.invoke(null,“ location”);对象mInterface = getInterface.invoke(null,(IBinder)iBindermInterface);

方法方法= mInterface.getClass()。getMethod(“ reportLocation”,Location.class,Boolean.class);

错误:

java.lang.NoSuchMethodException:android.location.ILocationManager $ Stub $ Proxy.reportLocation [class android.location.Location,class java.lang.Boolean]

[当我尝试从“ android.location.ILocationManager $ Stub”打印所有方法时,我没有看到此方法:

Class mStub = Class.forName(“ android.location.ILocationManager $ Stub”);Method [] getInterfaceAll = mStub.getMethods();for(方法getInt:getInterfaceAll)Log.d(LOG_TAG,“ getInt =” + getInt);

在Android P(SDK 28)中,我没有问题。

在Android Q(SDK 29)接口中,“ android.location.ILocationManager”没有“ reportLocation()”方法,相反,根据我的假设,接口“ com.android.internal.location.ILocationProviderManager”具有onReportLocation()。但是此接口包含抽象方法onReportLocation(),我无法获得其实现。

哪个接口包含此方法,或者它已被更改(重命名)为另一个方法?

java android reflection location android-binder
1个回答
0
投票

这是通过反射使用内部API的过程。

问题很简单,在Android 9的reportLocation(in Location location, boolean passive)界面中一直存在ILocationManager.aidl方法,请检查here

但是从Android 10开始,该方法已被删除,如内部部分here中所见

您可能应该更改代码以使用某些公共API,或者将很难扫描当前的API并找到替代品与反射配合使用。 (您仍然会冒着将他们列入黑名单的风险将来的API)

PS:仅是为了提供完整的信息,功能可能已移至here(我已经进行了一些提交,但这可能完全无法使用/不同,我真的不鼓励尝试使用它)]]

© www.soinside.com 2019 - 2024. All rights reserved.