def open_file(path): """ Open the specified file. On Android, for the ACTION_VIEW to work, the Uri supplied to the Intent has to be sanctioned by the FileProvider (i.e. Uri.fromFile does not work), so: - The legacy android.support.v4.content.FileProvider has to be added to the app because AndroidX is not yet supported by Kivy [1]. In practice, this means adding a gradle dependency in buildozer.spec. - The FileProvider requires a bit of boilerplate XML in the AndroidManifest and one other file [2]. As the second does not seem to be currently configurable via Buildozer, the latter is set to use a dedicated fork and branch of python-for-android [3]. [1]: https://github.com/kivy/python-for-android/issues/2020 [2]: https://developer.android.com/reference/android/support/v4/content/FileProvider [3]: https://github.com/pavelsof/python-for-android/tree/with-fileprovider """ mime_type, _ = mimetypes.guess_type(path) if PLATFORM == 'android': uri = FileProvider.getUriForFile(mActivity, 'com.pavelsof.wormhole.fileprovider', File(path)) intent = Intent() intent.setAction(Intent.ACTION_VIEW) intent.setDataAndType(uri, mime_type) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) mActivity.startActivity(intent)
def open_navigation(self, lon, lat, mode, *largs): s = f'google.navigation:q={lon},{lat}&mode={mode}' intent = Intent(Intent.ACTION_VIEW, Uri.parse(s)) intent.setPackage("com.google.android.apps.maps") if intent.resolveActivity(mActivity.getPackageManager()): mActivity.startActivity(intent) else: toast('No google maps found!\nInstall it from Play Store', 3)
def contact_developer(self, *largs): intent = Intent(Intent.ACTION_SENDTO) intent.setData(Uri.parse("mailto:")) intent.putExtra(Intent.EXTRA_EMAIL, [MAIL]) intent.putExtra(Intent.EXTRA_SUBJECT, String("Bug report")) if intent.resolveActivity(mActivity.getPackageManager()): mActivity.startActivity(intent) else: toast('No mail app found!', 3)
def share(self): if self.loca: url = f"https://www.google.com/maps/search/@{self.loca[0]},{self.loca[1]},10z/" sendIntent = Intent() sendIntent.setAction(Intent.ACTION_SEND) sendIntent.putExtra(Intent.EXTRA_TEXT, String(url)) sendIntent.setType("text/plain") shareIntent = Intent.createChooser(sendIntent, String('Share...')) mActivity.startActivity(shareIntent) else: toast('No location')
def share(self): if self.loca: url = f"{URL}{self.loca[0]},{self.loca[1]},10z/" sendIntent = Intent() sendIntent.setAction(Intent.ACTION_SEND) sendIntent.putExtra(Intent.EXTRA_TEXT, String(url)) sendIntent.setType("text/plain") shareIntent = Intent.createChooser(sendIntent, String('Share...')) mActivity.startActivity(shareIntent) else: toast('No location', True, 80)
def open_dir(path): """ Open the specified directory. """ if PLATFORM == 'android': intent = Intent() intent.setAction(Intent.ACTION_VIEW) intent.setDataAndType(Uri.parse(path), Document.MIME_TYPE_DIR) title = cast('java.lang.CharSequence', String('Open dir with')) mActivity.startActivity(Intent.createChooser(intent, title)) else: pass
def share_text(self, plain_text, app=None): try: self.plain_text = plain_text # for the gc self.send = Intent() self.send.setAction(Intent.ACTION_SEND) self.send.setType("text/plain") self.send.putExtra(Intent.EXTRA_TEXT, JString(self.plain_text)) if app: self.send.setPackage(app) mActivity.startActivity(self.send) else: self.send1 = Intent.createChooser(self.send, None) mActivity.startActivity(self.send1) Clock.schedule_once(self.begone_you_black_screen) except Exception as e: print('ERROR: ShareSnd().share_text()' + str(e))
def share_uri(self, uri, app=None): try: cr = mActivity.getContentResolver() self.MIME = cr.getType(uri) self.uri = uri self.parcelable = cast('android.os.Parcelable', self.uri) self.send = Intent() self.send.setAction(Intent.ACTION_SEND) self.send.setType(self.MIME) self.send.putExtra(Intent.EXTRA_STREAM, self.parcelable) self.send.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) if app: self.send.setPackage(app) mActivity.startActivity(self.send) else: self.send1 = Intent.createChooser(self.send, None) mActivity.startActivity(self.send1) Clock.schedule_once(self.begone_you_black_screen) except Exception as e: print('ERROR: ShareSnd().share_uri()' + str(e))
def enable(self, _): gpsIntent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS) mActivity.startActivity(gpsIntent)