1
我有一個長時間的點擊監聽器連接到一個webview,它裏面我獲得了與img
標籤相關聯的URL,在4.2.2和4.3中一切正常,但現在4.4上的消息數據url
是相同的src
的價值Kitkat不返回url for requestFocusNodeHref
這是一個錯誤?
public class ImagePickerActivity extends Activity implements OnLongClickListener {
...
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
webView = (WebView) findViewById(R.id.webview_view);
webView.setWebViewClient(...);
webView.setWebChromeClient(...);
webView.setOnLongClickListener(this);
}
@Override
public boolean onLongClick(View v) {
Message msg = new Message();
msg.setTarget(new LongClickHandler(this));
webView.requestFocusNodeHref(msg);
return false;
}
private final static class LongClickHandler extends Handler {
private final ImagePickerActivity activity;
public LongClickHandler(ImagePickerActivity activity) {
this.activity = activity;
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
String url = msg.getData().getString("url");
// as documentation says, three keys are returned: url, src and title
// but on kitkat 4.4 url and src are identical
// on 4.2.2 and 4.3 as written on docs url points to the anchor's href attribute and src to the img.src attribute
for (String s : msg.getData().keySet()) {
System.out
.println("ImagePickerActivity.LongClickHandler.handleMessage()" + s + " = " + msg.getData().get(s));
}
}
}
}
感謝您的長時間解釋,我無法編輯html內容,應用程序不從我的服務器讀取網頁。必須在我的webView設計上禁用JavaScript,所以我正在考慮自己解析HTML(使用jsoup ??),提取圖像並使用grivView顯示它們。我也提交了一個錯誤。 https://code.google.com/p/android/issues/detail?id=62928 – dafi
此錯誤已在https://code.google.com/p/chromium/issues/detail?id=323989中解決/解決截至2014年1月。不知道何時/如果該修補程序進入現有設備。 – MandisaW