如何使用反射在Android WebView中获取选定文本?
我正在尝试在Android中获取我的WebView的选定文本。我知道Android不允许我们使用正确的方法来实现这一点 我在互联网上找到的一个解决方案是使用反射。这是我正在使用的代码:如何使用反射在Android WebView中获取选定文本?,android,reflection,android-webview,Android,Reflection,Android Webview,我正在尝试在Android中获取我的WebView的选定文本。我知道Android不允许我们使用正确的方法来实现这一点 我在互联网上找到的一个解决方案是使用反射。这是我正在使用的代码: Region result = null; try { Object[] params = null; Method nativeGetSelection = WebView.class.getDeclaredMethod("nativeGetSelectio
Region result = null;
try {
Object[] params = null;
Method nativeGetSelection = WebView.class.getDeclaredMethod("nativeGetSelection");
nativeGetSelection.setAccessible(true);
result = (Region)nativeGetSelection.invoke(this, params);
} catch (Exception e) {
e.printStackTrace();
}
但我没有例外。但是Android WebView具有所需的nativeGetSelection方法。你怎么看
那么为什么会发生这种情况呢?不要使用反射来获取私有API。无论您的minSdk/targetSdk如何,这在Android 4.4 KitKat上都不起作用,因为该API根本不存在。如果使用反射的方法不在官方API中,您就不能指望这些方法。您在哪个版本的Android上运行此功能?我在清单中的minSdk版本是13。我认为问题在于版本,真的