0
我已經爲WebView添加了JavaScript接口。帶參數的WebView addJavascriptInterface函數
我能夠使用所有沒有參數的函數。
但是當我從JavaScript給參數。該功能不被WebView調用。
見代碼
的Javascript
function getCellString(row, column) {
return Report.getCellString(row,column);
}
的WebView
webView.addJavascriptInterface(new JavaScriptInterface(), "Report");
JavaScript接口,
public class JavaScriptInterface
{
public String getCellString(int row, int column)
{
return row + "," + column;
}
}
我不知道是否是因爲字符串返回類型或T他爲函數的參數。
EDITED
我想沒有給出參數的getCellString()仍是不被調用。
這意味着問題與返回類型。我給了不是原始數據類型的字符串返回類型。
任何人都可以告訴我什麼樣的數據類型應該代替字符串,以便它接受。
logcat的後addJavaScriptInterface
03-17 17:52:26.748: V/webcore(19908): ADD_JS_INTERFACE arg1=0 arg2=0 [email protected]
03-17 17:52:26.858: V/webcore(19908): LOAD_URL arg1=0 arg2=0 [email protected]
03-17 17:52:26.858: V/webcore(19908): CORE loadUrl file:///data/data/mypackage/cache/html_report/ReportHTML.html
03-17 17:52:26.858: V/webkit(19908): startLoadingResource: url=file:///data/data/mypackage/cache/html_report/ReportHTML.html, method=GET, postData=null, isMainFramePage=true, mainResource=true, userGesture=true
03-17 17:52:26.858: V/webkit(19908): LoadListener constructor url=file:///data/data/mypackage/cache/html_report/ReportHTML.html
03-17 17:52:26.868: V/webview(19908): WEBCORE_INITIALIZED_MSG_ID
03-17 17:52:26.868: V/webkit(19908): LoadListener: from: file:///data/data/mypackage/cache/html_report/ReportHTML.html major: 1 minor: 1 code: 200 reason: OK
03-17 17:52:26.878: V/webkit(19908): LoadListener.headers
03-17 17:52:26.878: V/webcore(19908): 200 arg1=0 arg2=0 obj=null
03-17 17:52:26.878: V/webkit(19908): LoadListener.data(): url: file:///data/data/mypackage/cache/html_report/ReportHTML.html
03-17 17:52:26.878: V/webkit(19908): LoadListener.data(): url: file:///data/data/mypackage/cache/html_report/ReportHTML.html
03-17 17:52:26.888: V/webkit(19908): LoadListener.endData(): url: file:///data/data/mypackage/cache/html_report/ReportHTML.html
03-17 17:52:26.898: V/webkit(19908): guessMimeTypeFromExtension: url = file:///data/data/mypackage/cache/html_report/ReportHTML.html
03-17 17:52:26.908: V/webview(19908): sendOurVisibleRect=(0,55,r=240,b=320
03-17 17:52:26.908: V/webview(19908): setCertificate=null
03-17 17:52:26.988: V/webkit(19908): LoadListener.detachRequestHandle(): requestHandle: null
03-17 17:52:27.098: V/webview(19908): SET_SCROLLBAR_MODES
03-17 17:52:27.098: V/webview(19908): SET_SCROLLBAR_MODES
03-17 17:52:27.098: V/webview(19908): SET_SCROLLBAR_MODES
03-17 17:52:27.098: V/webcore(19908): didFirstLayout standardLoad =true
03-17 17:52:27.108: V/webcore(19908): SET_SCROLL_OFFSET arg1=0 arg2=0 obj=Point(0, 0)
03-17 17:52:27.108: V/webview(19908): UPDATE_TEXT_ENTRY_MSG_ID
03-17 17:52:27.108: V/webcore(19908): SET_GLOBAL_BOUNDS arg1=0 arg2=0 obj=Rect(0, 55 - 240, 320)
03-17 17:52:27.118: V/webcore(19908): VIEW_SIZE_CHANGED arg1=0 arg2=0 [email protected]
03-17 17:52:27.118: V/webcore(19908): viewSizeChanged w=313; h=353; textwrapWidth=313; scale=0.75
03-17 17:52:27.118: V/webcore(19908): viewSizeChanged
03-17 17:52:27.118: V/webcore(19908): SET_ACTIVE arg1=0 arg2=0 obj=null
03-17 17:52:27.128: V/webcore(19908): WEBKIT_DRAW arg1=0 arg2=0 obj=null
03-17 17:52:27.128: V/webcore(19908): webkitDraw start
03-17 17:52:27.128: V/webcore(19908): webkitDraw NEW_PICTURE_MSG_ID
03-17 17:52:27.128: V/webcore(19908): UPDATE_CACHE_AND_TEXT_ENTRY arg1=0 arg2=0 obj=null
03-17 17:52:27.128: V/webview(19908): NEW_PICTURE_MSG_ID
03-17 17:52:27.128: V/webview(19908): NEW_PICTURE_MSG_ID {0,0,313,353}
03-17 17:52:27.128: V/webview(19908): UPDATE_TEXT_ENTRY_MSG_ID
03-17 17:53:28.266: V/websync(19908): *** WebSyncManager sync ***
03-17 17:53:28.266: V/websync(19908): CookieSyncManager::syncFromRamToFlash STARTS
03-17 17:53:28.268: V/websync(19908): CookieSyncManager::syncFromRamToFlash DONE
是'row'和'column'整數你的JavaScript代碼中的值?你在LogCat中看到任何消息嗎?返回一個'字符串'是沒有問題的 - 我有示例代碼可以做到這一點。 – CommonsWare 2012-03-17 12:19:48
如果您有String的示例代碼,請在解決方案中給出。 – 2012-03-17 12:23:37
此目錄包含一對使用'addJavaScriptInterface()'的項目:https://github.com/commonsguy/cw-advandroid/tree/master/WebView – CommonsWare 2012-03-17 12:46:08