문의 시, 사용하시는 개발환경과 디벨로퍼스 앱ID를 알려주세요.
안녕하세요.
ID 1095370
개발환경: 안드로이드 webview
안드로이드앱에서 webview를 띄우고, rest api를 통해 카카오 인증 시도시,
webiew에서 화면이 전혀 나오지 않고, 계속 아래의 페이지들을 호출합니다.
onPageFinished: 카카오계정
onPageFinished: 카카오계정
onPageFinished: 카카오계정
onPageFinished: 카카오계정
호출한 인증 url은 다음과 같습니다.
카카오계정<#######>&redirect_uri=<>
호출을 한번만 해도 계속, onpagefinished가 여러번 호출됩니다.
관련해서, 참고할만한 자료나 해결방안 알려주시면 감사하겠습니다.
참고로 코드는 다음과 같습니다.
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//kakao
//
FrameLayout webViewLayout;
WebView webView = view.findViewById(R.id.webView);
webViewLayout = view.findViewById(R.id.webview_frame);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setSupportMultipleWindows(true);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
WebView childWebView = new WebView(view.getContext());
Log.d("TAG", "Creating new WebView");
childWebView.getSettings().setJavaScriptEnabled(true);
childWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
childWebView.getSettings().setSupportMultipleWindows(true);
childWebView.setLayoutParams(view.getLayoutParams());
childWebView.setWebViewClient(view.getWebViewClient());
childWebView.setWebChromeClient(view.getWebChromeClient());
webViewLayout.addView(childWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(childWebView);
resultMsg.sendToTarget();
return true;
}
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
webViewLayout.removeView(window);
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.d(TAG, "onPageFinished: " + url);
if (url.startsWith(REDIRECT_URI)) {
Uri uri = Uri.parse(url);
String code = uri.getQueryParameter("code");
if (code != null) {
Log.d(TAG, "Authorization code: " + code);
// Exchange authorization code for access token
exchangeCodeForToken(code);
} else if (uri.getQueryParameter("error") != null) {
Log.e(TAG, "Error: " + uri.getQueryParameter("error"));
}
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Log.d("TAG url", request.getUrl().toString());
Log.d("TAG scheme", request.getUrl().getScheme());
if ("https".equals(request.getUrl().getScheme())) {
Log.d("SJCHOI4", "SJCHOI: " + request.getUrl().toString());
webView.loadUrl(request.getUrl().toString());
}
if ("intent".equals(request.getUrl().getScheme())) {
try {
Intent intent = Intent.parseUri(request.getUrl().toString(), Intent.URI_INTENT_SCHEME);
/*
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
Log.d(“TAG”, "ACTIVITY: " + intent.getPackage());
return true;
}
*/
String fallbackUrl = intent.getStringExtra(“browser_fallback_url”);
if (fallbackUrl != null) {
view.loadUrl(fallbackUrl);
Log.d(“TAG FALLBACK”, "FALLBACK: " + fallbackUrl);
Log.d(“SJCHOI5”, "SJCHOI: " + fallbackUrl);
return true;
}
Log.e("TAG", "Could not parse anything");
} catch (URISyntaxException e) {
Log.e("TAG", "Invalid intent request", e);
}
}
return false;
}
});
String authUrl = AUTH_URL + "?response_type=code"
+ "&client_id=" + CLIENT_ID
+ "&redirect_uri=" + REDIRECT_URI;
webView.loadUrl(authUrl);
}