Skip to content

Commit 3ed40ed

Browse files
fix: open external apps (#18)
* fix: open external apps * feat: implement new manifest * fix: revert android plufin version * fix: revert constants * feat: add urlScheme to contants + remove unecessary code * fix: move banks to constants and use var in constants --------- Co-authored-by: Thrashattack <henrique2092@gmail.com>
1 parent f6564a1 commit 3ed40ed

3 files changed

Lines changed: 63 additions & 13 deletions

File tree

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
<manifest
2-
xmlns:android="http://schemas.android.com/apk/res/android">
1+
<manifest
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
34
<uses-permission android:name="android.permission.INTERNET" />
45
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5-
<application>
6-
<activity
7-
android:name="flizpay2.flizpaysdk.lib.WebViewService"
8-
android:exported="true"
9-
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
10-
</application>
6+
<application>
7+
<activity
8+
android:name="flizpay2.flizpaysdk.lib.WebViewService"
9+
android:exported="true"
10+
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
11+
android:launchMode="singleTask"
12+
tools:node="merge">
13+
<intent-filter tools:node="merge">
14+
<action android:name="android.intent.action.VIEW" />
15+
<category android:name="android.intent.category.DEFAULT" />
16+
<category android:name="android.intent.category.BROWSABLE" />
17+
<data android:scheme="flizpaywebview" />
18+
</intent-filter>
19+
</activity>
20+
</application>
1121
</manifest>

flizpaysdk/src/main/kotlin/flizpay2/flizpaysdk/Constants.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,14 @@ package flizpay2.flizpaysdk
33
object Constants {
44
var API_URL: String = "https://api.flizpay.de"
55
var BASE_URL: String = "https://secure.flizpay.de"
6+
var URL_SCHEME: String = "flizpaywebview://"
7+
var NO_CREDS_BANKS = listOf(
8+
"ing-diba.de", // ING-DiBa
9+
"revolut.com", // Revolut
10+
"consorsbank.de", // Consorsbank
11+
"n26.com", // N26
12+
"tomorrow.one", // Tomorrow
13+
"kontist.com", // Kontist
14+
"finom.com" // Finom
15+
)
616
}

flizpaysdk/src/main/kotlin/flizpay2/flizpaysdk/lib/WebViewService.kt

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
package flizpay2.flizpaysdk.lib
22

33
import android.annotation.SuppressLint
4+
import android.content.Intent
45
import android.os.Bundle
56
import android.webkit.WebChromeClient
7+
import android.webkit.WebResourceRequest
68
import android.webkit.WebView
79
import android.webkit.WebViewClient
810
import androidx.appcompat.app.AppCompatActivity
11+
import flizpay2.flizpaysdk.Constants
912

10-
class WebViewService : AppCompatActivity() {
1113

14+
class WebViewService : AppCompatActivity() {
1215
@SuppressLint("SetJavaScriptEnabled")
1316
override fun onCreate(savedInstanceState: Bundle?) {
1417
super.onCreate(savedInstanceState)
1518

1619
// Get Intent Data
1720
val redirectUrl = intent.getStringExtra("redirectUrl") ?: return
21+
val urlScheme = Constants.URL_SCHEME
1822
val token = intent.getStringExtra("token") ?: return
1923

2024
// Instantiate WebView
@@ -25,18 +29,44 @@ class WebViewService : AppCompatActivity() {
2529
// Register WebViewBridge to intercept window.close()
2630
val webViewBridge = WebViewBridge(webView, this)
2731

32+
webView.webViewClient = object : WebViewClient() {
33+
34+
override fun shouldOverrideUrlLoading(
35+
view: WebView?,
36+
request: WebResourceRequest?
37+
): Boolean {
38+
val url = request?.url ?: return false
39+
val host = url.host ?: return false
40+
41+
// If the URL is HTTPS and host is in the noCredentialsBankHosts list,
42+
// open it externally instead of loading in WebView
43+
if (url.scheme.equals("https", ignoreCase = true) &&
44+
Constants.NO_CREDS_BANKS.any { host.contains(it) }
45+
) {
46+
val intent = Intent(Intent.ACTION_VIEW, url)
47+
if (intent.resolveActivity(packageManager) != null) {
48+
startActivity(intent)
49+
}
50+
return true // Cancel loading inside the WebView
51+
}
52+
return false // Allow the WebView to load the URL
53+
}
54+
}
55+
56+
2857
runOnUiThread {
2958
webView.webChromeClient = WebChromeClient()
30-
webView.webViewClient = WebViewClient()
31-
59+
3260
// Set content
3361
setContentView(webView)
3462

3563
// Load redirect URL with token
36-
val redirectUrlWithJwtToken = "$redirectUrl&jwt=$token"
64+
val redirectUrlWithJwtToken = "$redirectUrl&jwt=$token&redirect-url=$urlScheme"
65+
66+
// Load the URL
3767
webView.loadUrl(redirectUrlWithJwtToken)
3868

39-
// Override window.close behavior
69+
// Override window.close behavior if needed
4070
webViewBridge.overrideWindowClose()
4171
}
4272
}

0 commit comments

Comments
 (0)