Skip to content

Commit 67875c0

Browse files
vesellovAndroid-for-Python
authored andcommitted
added ShareSheet().view_file() method
1 parent 2c66eaa commit 67875c0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Diff for: README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This package contains three classes, `SharedStorage`, `ShareSheet`, and `Chooser
2121

2222
- `SharedStorage` allows copying files to and from shared storage with the `copy_to_shared()`, `copy_from_shared()`, and `delete_shared()` methods.
2323

24-
- `ShareSheet` allows sending plain text, or a 'shared file' to another app. Using the `share_plain_text()`, `share_file()`, and `share_file_list()` methods, these create an Android ShareSheet used to select the target app.
24+
- `ShareSheet` allows sending plain text, or a 'shared file' to another app. Using the `share_plain_text()`, `share_file()`, and `share_file_list()` methods, these create an Android ShareSheet used to select the target app. You can also call the `view_file()` method to open a 'shared file' in another app - Android will try to use default application available for that specific file type.
2525

2626
- `Chooser` allows selecting a 'shared file' using the Android Chooser UI. The callback returns a list of one or more shared files.
2727

@@ -138,6 +138,8 @@ Enables sending either plain_text, a file, or a file list to another app. The ta
138138
def share_file(self, shared_file, app = None):
139139

140140
def share_file_list(self, shared_file_list, app = None):
141+
142+
def view_file(self, shared_file):
141143
```
142144

143145
`plain_text` is a string.

Diff for: src/androidstorage4kivy/sharesheet.py

+18
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ def share_file(self, shared_file, app = None):
6565
Logger.warning('ShareSheet().share_file()')
6666
Logger.warning(str(e))
6767

68+
def view_file(self, shared_file):
69+
try:
70+
self._cleanup_legacy_uri_list()
71+
if shared_file == None:
72+
return
73+
uri = self._legacy_create_uri(shared_file)
74+
if uri == None:
75+
return
76+
cr = mActivity.getContentResolver()
77+
self.MIME = cr.getType(uri)
78+
self.send = Intent()
79+
self.send.setAction(Intent.ACTION_VIEW)
80+
self.send.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
81+
self.send.setDataAndType(uri, self.MIME)
82+
mActivity.startActivity(self.send)
83+
except Exception as e:
84+
Logger.warning('ShareSheet().view_file()')
85+
Logger.warning(str(e))
6886

6987
def share_file_list(self, shared_file_list, app = None):
7088
try:

0 commit comments

Comments
 (0)