我正在尝试在安卓系统中获取我的WebView的选定文本。我知道Android不会让我们用正确的方式来获得它。
我在互联网上找到的一个解决方案是使用反射。这是我使用的代码:
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();
}但我得到了NoSuchMethodException。但是Android的WebView有它想要的方法(nativeGetSelection)。如何看待here
那么为什么会发生这种情况呢?
发布于 2014-03-25 18:51:59
不要使用反射来获取私有API。这在Android4.4 (KitKat)上是行不通的,不管你的minSdk/targetSdk是什么,因为它根本就不存在。
https://stackoverflow.com/questions/22541634
复制相似问题