Skip to content

Commit 5f5b61a

Browse files
committed
fix: improve app root path retrieval and error handling
1 parent 8fe4fc8 commit 5f5b61a

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

android_notify/core.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,23 @@ def get_activity_class_name():
5353

5454

5555
def get_app_root_path():
56+
path = ''
5657
if on_flet_app():
57-
return os.path.join(context.getFilesDir().getAbsolutePath(),'flet')
58+
path= os.path.join(context.getFilesDir().getAbsolutePath(),'flet')
5859
else:
59-
from android.storage import app_storage_path # type: ignore
60-
return app_storage_path()
61-
60+
try:
61+
from android.storage import app_storage_path # type: ignore
62+
path = app_storage_path()
63+
except Exception as e:
64+
print('android-notify- Error getting apk main file path: ',e)
65+
return './'
66+
return os.path.join(path,'app')
67+
6268
def asks_permission_if_needed():
6369
"""
6470
Ask for permission to send notifications if needed.
6571
"""
6672
if on_flet_app():
67-
VERSION_CODES = autoclass('android.os.Build$VERSION_CODES')
6873
ContextCompat = autoclass('androidx.core.content.ContextCompat')
6974
# if you get error `Failed to find class: androidx/core/app/ActivityCompat`
7075
#in proguard-rules.pro add `-keep class androidx.core.app.ActivityCompat { *; }`
@@ -94,7 +99,7 @@ def get_image_uri(relative_path):
9499
:return: Absolute URI java Object (e.g., 'file:///path/to/file.png').
95100
"""
96101
app_root_path = get_app_root_path()
97-
output_path = os.path.join(app_root_path,'app', relative_path)
102+
output_path = os.path.join(app_root_path, relative_path)
98103
# print(output_path,'output_path') # /data/user/0/org.laner.lan_ft/files/app/assets/imgs/icon.png
99104

100105
if not os.path.exists(output_path):

0 commit comments

Comments
 (0)