处理game center为 本地webview加载后再跳转
This commit is contained in:
parent
1e487a4f8d
commit
5d49ce6a96
|
|
@ -1,6 +1,5 @@
|
||||||
package com.gamedog.vididin.features.game
|
package com.gamedog.vididin.features.game
|
||||||
|
|
||||||
import android.R.attr.scheme
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
|
@ -60,9 +59,9 @@ class GameCenterActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(),
|
||||||
|
|
||||||
with(webView) {
|
with(webView) {
|
||||||
settings.javaScriptEnabled = true
|
settings.javaScriptEnabled = true
|
||||||
webView.addJavascriptInterface(WebAppInterface(this@GameCenterActivity), "com.viddin.videos.free")
|
webView.addJavascriptInterface(WebAppInterface(this@GameCenterActivity, webView), "com.viddin.videos.free")
|
||||||
|
|
||||||
/*webViewClient = object : WebViewClient() {
|
webViewClient = object : WebViewClient() {
|
||||||
override fun shouldOverrideUrlLoading(
|
override fun shouldOverrideUrlLoading(
|
||||||
view: WebView?,
|
view: WebView?,
|
||||||
request: WebResourceRequest
|
request: WebResourceRequest
|
||||||
|
|
@ -71,6 +70,13 @@ class GameCenterActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(),
|
||||||
if (!request.url.toString().startsWith("intent")) {
|
if (!request.url.toString().startsWith("intent")) {
|
||||||
view?.loadUrl(url.toString())
|
view?.loadUrl(url.toString())
|
||||||
return true
|
return true
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
handleIntentUrl(url.toString())
|
||||||
|
return true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
@ -85,7 +91,7 @@ class GameCenterActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(),
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -138,6 +144,63 @@ class GameCenterActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(),
|
||||||
//TODO("Not yet implemented")
|
//TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleIntentUrl(url: String) {
|
||||||
|
var intent: Intent? = null
|
||||||
|
if (url.startsWith("intent")) {
|
||||||
|
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intent != null) {
|
||||||
|
if (isHw()) {
|
||||||
|
intent.setPackage(getDefaultBrowser())
|
||||||
|
}
|
||||||
|
intent.addCategory(Intent.CATEGORY_BROWSABLE)
|
||||||
|
intent.setComponent(null)
|
||||||
|
intent.setFlags(FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
}
|
||||||
|
this.startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isHw(): Boolean {
|
||||||
|
return "huawei".equals(Build.MANUFACTURER, ignoreCase = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getDefaultBrowser(): String? {
|
||||||
|
var packageName: String? = null
|
||||||
|
var systemApp: String? = null
|
||||||
|
var userApp: String? = null
|
||||||
|
val userAppList: MutableList<String?> = ArrayList<String?>()
|
||||||
|
val context: Context = BaseApp.appContext()
|
||||||
|
val browserIntent = Intent("android.intent.action.VIEW", Uri.parse("https://"))
|
||||||
|
val resolveInfo = context.getPackageManager()
|
||||||
|
.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY)
|
||||||
|
if (resolveInfo != null && resolveInfo.activityInfo != null) {
|
||||||
|
packageName = resolveInfo.activityInfo.packageName
|
||||||
|
}
|
||||||
|
if (packageName == null || packageName == "android") {
|
||||||
|
val lists = context.getPackageManager().queryIntentActivities(browserIntent, 0)
|
||||||
|
for (app in lists) {
|
||||||
|
if ((app.activityInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0) {
|
||||||
|
systemApp = app.activityInfo.packageName
|
||||||
|
} else {
|
||||||
|
userApp = app.activityInfo.packageName
|
||||||
|
userAppList.add(userApp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (userAppList.contains("com.android.chrome")) {
|
||||||
|
packageName = "com.android.chrome"
|
||||||
|
} else {
|
||||||
|
if (systemApp != null) {
|
||||||
|
packageName = systemApp
|
||||||
|
}
|
||||||
|
if (userApp != null) {
|
||||||
|
packageName = userApp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return packageName
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
internal fun startActivity(activity: Activity) {
|
internal fun startActivity(activity: Activity) {
|
||||||
|
|
@ -148,7 +211,7 @@ class GameCenterActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class WebAppInterface(private val context: Activity) {
|
class WebAppInterface(private val context: Activity, private val webView: WebView) {
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
fun openBrowser(url: String) {
|
fun openBrowser(url: String) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -168,6 +231,7 @@ class WebAppInterface(private val context: Activity) {
|
||||||
}
|
}
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue