문의 시, 사용하시는 SDK 버전 정보와 디벨로퍼스 앱ID를 알려주세요.
SDK 버전 : 2.7.1
디벨로퍼스 앱ID : 970376
nextjs, flutter webview 로 구현된 상태인데요.
안드로이드 기종에서 카카오 로그인 버튼을 눌렀을 때 오류가 발생합니다…
웹페이지를 사용할 수 없음
intent:#Intent;action=com.kakao.talk.intent.action.CAPRI_LOGGED_IN_ACTIVITY; ...
아래는 코드입니다
// src/pages/_document.jsx
<script
src="https://t1.kakaocdn.net/kakao_js_sdk/2.7.1/kakao.min.js"
integrity="sha384-kDljxUXHaJ9xAb2AzRd59KxjrFjzHa5TAoFQ6GbYTCAG0bjM55XohjjDT7tDDC01"
crossorigin="anonymous"
/>
// src/pages/_app.tsx
const authorizeWithKakaoSDK = () => {
window.Kakao.Auth.authorize({
redirectUri: `${window.location.protocol}//${window.location.host}/kakao-redirect`,
});
startLoading();
};
<!-- android/app/src/main/AndroidManifest.xml -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.url_launcher_example">
<queries>
<!-- If your app opens https URLs -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
</intent>
<package android:name="com.kakao.talk" />
</queries>
<application
android:label="@string/app_name"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
// lib/main.dart
class _WebViewExampleState extends State<WebViewExample> {
late final WebViewController _controller;
@override
void initState() {
_controller = WebViewController()
..loadRequest(Uri.parse('https://dev.semutong.com'))
..setJavaScriptMode(JavaScriptMode.unrestricted)
..addJavaScriptChannel('OpenDeepLink', onMessageReceived: openDeepLink)
..addJavaScriptChannel('InitJS', onMessageReceived: runInitFlutterInJS);
super.initState();
}
void runInitFlutterInJS(JavaScriptMessage message) {
_controller.runJavaScript('window.initFlutter()');
}
void openDeepLink(JavaScriptMessage message) {
launchUrl(Uri.parse(message.message));
}
@override
Widget build(BuildContext context) {
return WillPopScope(
child: Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: WebViewWidget(controller: _controller),
),
),
onWillPop: () {
var future = _controller.canGoBack();
future.then((canGoBack) {
if (canGoBack) {
_controller.goBack();
} else {
SystemNavigator.pop();
}
});
return Future.value(false);
});
}
}
// android/app/src/main/kotlin/com/semutong/mobile/MainActivity.kt
package com.semutong.mobile
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
inner class MyWebViewClient : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
if (request?.url?.scheme == "intent") {
try {
val intent = Intent.parseUri(request.url.toString(), Intent.URI_INTENT_SCHEME)
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
return true
}
val fallbackUrl = intent.getStringExtra("browser_fallback_url")
if (fallbackUrl != null) {
view?.loadUrl(fallbackUrl)
return true
}
} catch (e: Exception) {
Log.e("MainActivity", "Error loading intent URL", e)
}
}
// 나머지 서비스 로직 구현
return false
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val webView = WebView(this)
webView.webViewClient = MyWebViewClient()
}
}