Skip to content

Commit

Permalink
Struggling with opening damn epub file after generation on android
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdanbobrowski committed Nov 1, 2024
1 parent 4b60f4a commit a5cd4a6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
7 changes: 7 additions & 0 deletions android_extra_manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.bohdanbobrowski.blog2epub"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/>
</provider>
12 changes: 9 additions & 3 deletions blog2epub/blog2epub_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,15 @@ def _open_epub(self, file_full_path, inst):
if platform == "win":
os.startfile(file_full_path) # type: ignore
elif platform == "android":
file_provider = autoclass("android.support.v4.content.FileProvider")
print(file_provider)
webbrowser.open(f"content://{file_full_path}")
File = autoclass("java.io.File")
FileProvider = autoclass("android.support.v4.content.FileProvider")
Context = autoclass("android.content.Context")
content_uri = FileProvider.getUriForFile(
Context,
"com.bohdanbobrowski.blog2epub",
File(file_full_path),
)
webbrowser.open(content_uri)
else:
opener = "open" if sys.platform == "osx" else "xdg-open"
subprocess.call([opener, file_full_path])
Expand Down
8 changes: 4 additions & 4 deletions buildozer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ android.permissions = android.permission.INTERNET, android.permission.WRITE_EXTE
#android.minapi = 21

# (int) Android SDK version to use
#android.sdk = 20
android.sdk = 18

# (str) Android NDK version to use
#android.ndk = 23b
Expand Down Expand Up @@ -147,11 +147,11 @@ android.permissions = android.permission.INTERNET, android.permission.WRITE_EXTE

# (str) Extra xml to write directly inside the <manifest> element of AndroidManifest.xml
# use that parameter to provide a filename from where to load your custom XML code
#android.extra_manifest_xml = ./src/android/extra_manifest.xml
# android.extra_manifest_xml = ./android_extra_manifest.xml

# (str) Extra xml to write directly inside the <manifest><application> tag of AndroidManifest.xml
# use that parameter to provide a filename from where to load your custom XML arguments:
#android.extra_manifest_application_arguments = ./src/android/extra_manifest_application_arguments.xml
# android.extra_manifest_application_arguments = ./android_extra_manifest.xml

# (str) Full name including package path of the Java class that implements Python Service
# use that parameter to set custom Java class which extends PythonService
Expand All @@ -167,7 +167,7 @@ android.permissions = android.permission.INTERNET, android.permission.WRITE_EXTE
#android.whitelist_src =

# (str) Path to a custom blacklist file
#android.blacklist_src =
# android.blacklist_src = ./tests/*.py

# (list) List of Java .jar files to add to the libs so that pyjnius can access
# their classes. Don't add jars that you do not need, since extra jars can slow
Expand Down

0 comments on commit a5cd4a6

Please sign in to comment.