내 응용 프로그램 웹보기가 포함 된 활동이 있습니다. 연결 서버를 열어달라고 요청하면 웹 리디렉션이되지만 웹보기가 나타나지 않고 페이지를 찾을 수 없음을 알리는 메시지가 표시됩니다. 내 PC의 브라우저에서 URL을 테스트하면 다음 페이지로 이동합니다. 그러나, webView에서는 두 번째 페이지로 연결되지 않았습니다. 내 흐름은 다음과 같이해야합니다 : 1 개방의 URL 2 서버는 응용 프로그램 3- 받고 서버 응답에 의해 해당 페이지에 다음 URL에 3 충전 로그인 양식을 지시Android, WebView에서 리디렉션 이벤트를받는 방법?
내 코드는 다음과 같다 :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_loginweb);
Log.i(TAG, "Try to create activity...");
final String userId = PropertyManager.getUserId();
final String password = PropertyManager.getPassword();
Log.i(TAG, "Id: " + userId + ", Password: " + password);
final WebView webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.addJavascriptInterface(new JavaScriptInterface(this), "JsInterface");
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
webView.loadUrl("javascript:document.LoginForm.tempusername.value = '" + userId + "';");
webView.loadUrl("javascript:document.LoginForm.password.value = '" + password + "';");
webView.loadUrl("javascript:document.LoginForm.Submit.click();");
webView.loadUrl("javascript:window.JsInterface.processHTML(document.getElementsByTagName('html')[0].innerHTML);");
String currentUrl = webView.getUrl();
Log.i(TAG, "current Url is: " + currentUrl);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
super.shouldOverrideUrlLoading(view, url);
Log.i(TAG, "redirect to: " + url);
view.loadUrl(url);
return false;
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
Log.i(TAG, "error code is:" + errorCode);
}
});
webView.loadUrl(PropertyManager.getLoginPageURL());
}
/*
* To bind a new interface between our JavaScript and Android code, call addJavascriptInterface(),
* passing it a class instance to bind to JavaScript of login page and an interface name that
* JavaScript can call to access the class.
*/
public class JavaScriptInterface {
Context mContext;
/** Instantiate the interface and set the context */
JavaScriptInterface(Context c) {
mContext = c;
}
/** process the html as needed by the app */
public void processHTML(String html) {
Log.i(TAG, "Processing HTML...");
Log.i(TAG, "content of page: " + html);
}
/** Show a toast from the web page */
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
내 문제는 shouldOverrideUrlLoading()
메서드는 절대로 리디렉션하는 동안 호출하지 않습니다. 어떤 제안이라도 인정 될 것입니다. 감사.