net::ERR_UNKNOWN_URL_SCHEME webview

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//자바
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("intent://")) {
try {
Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
Intent existPackage = getPackageManager().getLaunchIntentForPackage(intent.getPackage());
if (existPackage != null) {
startActivity(intent);
} else {
Intent marketIntent = new Intent(Intent.ACTION_VIEW);
marketIntent.setData(Uri.parse("market://details?id=" + intent.getPackage()));
startActivity(marketIntent);
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
} else if (url != null && url.startsWith("market://")) {
try {
Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
if (intent != null) {
startActivity(intent);
}
return true;
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
view.loadUrl(url);
return false;
}

// 코틀린
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
if (url != null && url.startsWith("intent://")) {
try {
val intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME)
val existPackage =
packageManager.getLaunchIntentForPackage(intent.getPackage()!!)
if (existPackage != null) {
startActivity(intent)
} else {
val marketIntent = Intent(Intent.ACTION_VIEW)
marketIntent.data =
Uri.parse("market://details?id=" + intent.getPackage()!!)
startActivity(marketIntent)
}
return true
} catch (e: Exception) {
e.printStackTrace()
}

} else if (url != null && url.startsWith("market://")) {
try {
val intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME)
if (intent != null) {
startActivity(intent)
}
return true
} catch (e: URISyntaxException) {
e.printStackTrace()
}

}
view.loadUrl(url)
return false
}