[Android] License: Open external links in browser app

Diego Fernando Nieto git at videolan.org
Sun Jun 28 16:51:43 CEST 2020


vlc-android | branch: master | Diego Fernando Nieto <diegofn at me.com> | Sat Jun 20 08:57:37 2020 -0500| [4074ef1eb2d0085eab198e37847d58c321d1eadc] | committer: Jean-Baptiste Kempf

License: Open external links in browser app

> https://code.videolan.org/videolan/vlc-android/commit/4074ef1eb2d0085eab198e37847d58c321d1eadc
---

 .../java/org/videolan/television/ui/LicenceActivity.kt  | 16 ++++++++++++++++
 .../src/org/videolan/vlc/gui/AboutFragment.kt           | 17 +++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/application/television/src/main/java/org/videolan/television/ui/LicenceActivity.kt b/application/television/src/main/java/org/videolan/television/ui/LicenceActivity.kt
index 7c53370aa..eca3f445a 100644
--- a/application/television/src/main/java/org/videolan/television/ui/LicenceActivity.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/LicenceActivity.kt
@@ -1,6 +1,8 @@
 package org.videolan.television.ui
 
 import android.annotation.SuppressLint
+import android.content.Intent
+import android.net.Uri
 import android.os.Bundle
 import android.util.Base64
 import android.view.View
@@ -34,6 +36,16 @@ class LicenceActivity : FragmentActivity() {
                 super.onPageFinished(view, url)
 
             }
+
+            override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
+                if (url.contains("file://")) {
+                    view.loadUrl(url)
+                } else {
+                    val i = Intent(Intent.ACTION_VIEW, Uri.parse(url))
+                    startActivity(i)
+                }
+                return true
+            }
         }
         setContentView(webView)
         (webView.layoutParams as? FrameLayout.LayoutParams)?.let {
@@ -57,6 +69,8 @@ class LicenceActivity : FragmentActivity() {
                     "style.innerHTML = window.atob('" + encoded + "');" +
                     "parent.appendChild(style);" +
                     "})()")
+
+            webView.settings.javaScriptEnabled = false
         } catch (e: Exception) {
             e.printStackTrace()
         }
@@ -73,6 +87,8 @@ class LicenceActivity : FragmentActivity() {
                     "link.setAttribute('href', newLink);" +
                     "link.innerText = newLink;" +
                     "})()")
+
+            webView.settings.javaScriptEnabled = false
         } catch (e: Exception) {
             e.printStackTrace()
         }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/AboutFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/AboutFragment.kt
index 734711d99..f06313c1e 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/AboutFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/AboutFragment.kt
@@ -21,7 +21,9 @@
 package org.videolan.vlc.gui
 
 import android.annotation.SuppressLint
+import android.content.Intent
 import android.content.res.Configuration
+import android.net.Uri
 import android.os.Bundle
 import android.util.Base64
 import android.view.LayoutInflater
@@ -45,6 +47,7 @@ import org.videolan.vlc.R
 import org.videolan.vlc.gui.audio.AudioPagerAdapter
 import org.videolan.vlc.gui.helpers.UiTools
 
+
 private const val TAG = "VLC/AboutFragment"
 private const val MODE_TOTAL = 2 // Number of audio browser modes
 
@@ -100,6 +103,16 @@ class AboutFragment : Fragment() {
                     }
                     super.onPageFinished(view, url)
                 }
+
+                override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
+                    if (url.contains("file://")) {
+                        view.loadUrl(url)
+                    } else {
+                        val i = Intent(Intent.ACTION_VIEW, Uri.parse(url))
+                        startActivity(i)
+                    }
+                    return true
+                }
             }
         }
     }
@@ -121,6 +134,8 @@ class AboutFragment : Fragment() {
                     "style.innerHTML = window.atob('" + encoded + "');" +
                     "parent.appendChild(style);" +
                     "})()")
+
+            webView.settings.javaScriptEnabled = false
         } catch (e: Exception) {
             e.printStackTrace()
         }
@@ -137,6 +152,8 @@ class AboutFragment : Fragment() {
                     "link.setAttribute('href', newLink);" +
                     "link.innerText = newLink;" +
                     "})()")
+
+            webView.settings.javaScriptEnabled = false
         } catch (e: Exception) {
             e.printStackTrace()
         }



More information about the Android mailing list