Skip to content

Commit

Permalink
better error message for webview
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Jan 21, 2024
1 parent 6d05fb4 commit efb346d
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.view.animation.OvershootInterpolator
import android.webkit.WebView
import android.widget.AdapterView
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
Expand Down Expand Up @@ -139,13 +140,27 @@ class NovelReaderActivity : AppCompatActivity(), EbookReaderEventListener {
}


@SuppressLint("WebViewApiAvailability")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//check for supported webview
val webViewVersion = WebViewCompat.getCurrentWebViewPackage(this)?.versionName
val webViewVersion = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
WebView.getCurrentWebViewPackage()?.versionName
} else {
WebViewCompat.getCurrentWebViewPackage(this)?.versionName
}
val firstVersion = webViewVersion?.split(".")?.firstOrNull()?.toIntOrNull()
if (webViewVersion == null || firstVersion == null || firstVersion < 87) {
Toast.makeText(this, "Please update WebView from PlayStore", Toast.LENGTH_LONG).show()
val text = if (webViewVersion == null) {
"Could not find webView installed"
} else if (firstVersion == null) {
"Could not find WebView Version Number: $webViewVersion"
} else if (firstVersion < 87) { //false positive?
"Webview Versiom: $firstVersion. PLease update"
} else {
"Please update WebView from PlayStore"
}
Toast.makeText(this, text, Toast.LENGTH_LONG).show()
//open playstore
val intent = Intent(Intent.ACTION_VIEW)
intent.data =
Expand Down

0 comments on commit efb346d

Please sign in to comment.