Skip to content

Commit 548a908

Browse files
authored
Merge pull request kivy#2387 from obfusk/webview-ext-browser
webview: add mOpenExternalLinksInBrowser field
2 parents 3850b72 + 4045557 commit 548a908

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import android.webkit.WebViewClient;
3636
import android.webkit.WebView;
37+
import android.net.Uri;
3738

3839
import org.renpy.android.ResourceManager;
3940

@@ -45,6 +46,7 @@ public class PythonActivity extends Activity {
4546
private static final String TAG = "PythonActivity";
4647

4748
public static PythonActivity mActivity = null;
49+
public static boolean mOpenExternalLinksInBrowser = false;
4850

4951
/** If shared libraries (e.g. SDL or the native application) could not be loaded. */
5052
public static boolean mBrokenLibraries;
@@ -163,6 +165,13 @@ public void onClick(DialogInterface dialog,int id) {
163165
mWebView.setWebViewClient(new WebViewClient() {
164166
@Override
165167
public boolean shouldOverrideUrlLoading(WebView view, String url) {
168+
if (mOpenExternalLinksInBrowser) {
169+
if (!(url.startsWith("file:") || url.startsWith("http://127.0.0.1:"))) {
170+
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
171+
startActivity(i);
172+
return true;
173+
}
174+
}
166175
view.loadUrl(url);
167176
return false;
168177
}

0 commit comments

Comments
 (0)