Mercurial > libervia-desktop-kivy
comparison cagou/core/platform_/android.py @ 345:a3cefa7158dc
android: open "geo:" URL using an Intent
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 04 Jan 2020 16:24:57 +0100 |
parents | 89799148f894 |
children | 4d3a0c4f2430 |
comparison
equal
deleted
inserted
replaced
344:83697218b9b2 | 345:a3cefa7158dc |
---|---|
20 import os | 20 import os |
21 import socket | 21 import socket |
22 from jnius import autoclass, cast | 22 from jnius import autoclass, cast |
23 from android import activity | 23 from android import activity |
24 from sat.core import log as logging | 24 from sat.core import log as logging |
25 from urllib.parse import urlparse | |
25 from cagou.core.constants import Const as C | 26 from cagou.core.constants import Const as C |
26 from cagou import G | 27 from cagou import G |
27 from kivy.clock import Clock | 28 from kivy.clock import Clock |
28 from .base import Platform as BasePlatform | 29 from .base import Platform as BasePlatform |
29 | 30 |
30 | 31 |
31 log = logging.getLogger(__name__) | 32 log = logging.getLogger(__name__) |
32 | 33 |
33 service = autoclass('org.salutatoi.cagou.ServiceBackend') | 34 service = autoclass('org.salutatoi.cagou.ServiceBackend') |
34 mActivity = autoclass('org.kivy.android.PythonActivity').mActivity | 35 mActivity = autoclass('org.kivy.android.PythonActivity').mActivity |
36 Intent = autoclass('android.content.Intent') | |
37 AndroidString = autoclass('java.lang.String') | |
38 Uri = autoclass('android.net.Uri') | |
35 ImagesMedia = autoclass('android.provider.MediaStore$Images$Media') | 39 ImagesMedia = autoclass('android.provider.MediaStore$Images$Media') |
36 AudioMedia = autoclass('android.provider.MediaStore$Audio$Media') | 40 AudioMedia = autoclass('android.provider.MediaStore$Audio$Media') |
37 VideoMedia = autoclass('android.provider.MediaStore$Video$Media') | 41 VideoMedia = autoclass('android.provider.MediaStore$Video$Media') |
42 | |
38 DATA = '_data' | 43 DATA = '_data' |
39 | 44 |
40 | 45 |
41 STATE_RUNNING = b"running" | 46 STATE_RUNNING = b"running" |
42 STATE_PAUSED = b"paused" | 47 STATE_PAUSED = b"paused" |
112 return uri.getPath() | 117 return uri.getPath() |
113 return cursor.getString(col_idx) | 118 return cursor.getString(col_idx) |
114 | 119 |
115 def on_new_intent(self, intent): | 120 def on_new_intent(self, intent): |
116 log.debug("on_new_intent") | 121 log.debug("on_new_intent") |
117 Intent = autoclass('android.content.Intent') | |
118 action = intent.getAction(); | 122 action = intent.getAction(); |
119 intent_type = intent.getType(); | 123 intent_type = intent.getType(); |
120 if action == "android.intent.action.SEND": | 124 if action == Intent.ACTION_SEND: |
121 # we have receiving data to share, we parse the intent data | 125 # we have receiving data to share, we parse the intent data |
122 # and show the share widget | 126 # and show the share widget |
123 data = {} | 127 data = {} |
124 text = intent.getStringExtra(Intent.EXTRA_TEXT) | 128 text = intent.getStringExtra(Intent.EXTRA_TEXT) |
125 if text is not None: | 129 if text is not None: |
147 f"text: {text}\n" | 151 f"text: {text}\n" |
148 f"uri: {uri}\n" | 152 f"uri: {uri}\n" |
149 f"path: {path}") | 153 f"path: {path}") |
150 | 154 |
151 log.debug(msg) | 155 log.debug(msg) |
156 | |
157 def open_url(self, url, wid=None): | |
158 parsed_url = urlparse(url) | |
159 if parsed_url.scheme == "geo": | |
160 intent = Intent(Intent.ACTION_VIEW) | |
161 intent.setData(Uri.parse(url)) | |
162 if mActivity.getPackageManager() is not None: | |
163 activity = cast('android.app.Activity', mActivity) | |
164 activity.startActivity(intent) | |
165 else: | |
166 super().open_url(self, url, wid) |