changeset 345:a3cefa7158dc

android: open "geo:" URL using an Intent
author Goffi <goffi@goffi.org>
date Sat, 04 Jan 2020 16:24:57 +0100
parents 83697218b9b2
children 7b9a0e57df53
files cagou/core/platform_/android.py
diffstat 1 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/platform_/android.py	Sat Jan 04 16:24:57 2020 +0100
+++ b/cagou/core/platform_/android.py	Sat Jan 04 16:24:57 2020 +0100
@@ -22,6 +22,7 @@
 from jnius import autoclass, cast
 from android import activity
 from sat.core import log as logging
+from urllib.parse import urlparse
 from cagou.core.constants import Const as C
 from cagou import G
 from kivy.clock import Clock
@@ -32,9 +33,13 @@
 
 service = autoclass('org.salutatoi.cagou.ServiceBackend')
 mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
+Intent = autoclass('android.content.Intent')
+AndroidString = autoclass('java.lang.String')
+Uri = autoclass('android.net.Uri')
 ImagesMedia = autoclass('android.provider.MediaStore$Images$Media')
 AudioMedia = autoclass('android.provider.MediaStore$Audio$Media')
 VideoMedia = autoclass('android.provider.MediaStore$Video$Media')
+
 DATA = '_data'
 
 
@@ -114,10 +119,9 @@
 
     def on_new_intent(self, intent):
         log.debug("on_new_intent")
-        Intent = autoclass('android.content.Intent')
         action = intent.getAction();
         intent_type = intent.getType();
-        if action == "android.intent.action.SEND":
+        if action == Intent.ACTION_SEND:
             # we have receiving data to share, we parse the intent data
             # and show the share widget
             data = {}
@@ -149,3 +153,14 @@
                f"path: {path}")
 
         log.debug(msg)
+
+    def open_url(self, url, wid=None):
+        parsed_url = urlparse(url)
+        if parsed_url.scheme == "geo":
+            intent = Intent(Intent.ACTION_VIEW)
+            intent.setData(Uri.parse(url))
+            if mActivity.getPackageManager() is not None:
+                activity = cast('android.app.Activity', mActivity)
+                activity.startActivity(intent)
+        else:
+            super().open_url(self, url, wid)