From d7a62aa4c1d3149e4f2a5fea35b09517d940cb4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=E1=B4=87C=E1=B4=8F=E1=B4=85=E1=B4=87s2=E1=B4=8D=E1=B4=9C?= =?UTF-8?q?=E1=B4=84=CA=9C?= Date: Thu, 5 Dec 2024 07:45:25 +0000 Subject: [PATCH] Fix: Testing a fix for calendar apps --- .../common/ContextExtensions.kt | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/github/droidworksstudio/common/ContextExtensions.kt b/app/src/main/java/com/github/droidworksstudio/common/ContextExtensions.kt index caf961b..8e91f3b 100644 --- a/app/src/main/java/com/github/droidworksstudio/common/ContextExtensions.kt +++ b/app/src/main/java/com/github/droidworksstudio/common/ContextExtensions.kt @@ -304,22 +304,16 @@ fun Context.launchClock() { fun Context.launchCalendar() { try { - val cal: Calendar = Calendar.getInstance() - cal.time = Date() - val time = cal.time.time - val builder: Uri.Builder = CalendarContract.CONTENT_URI.buildUpon() - builder.appendPath("time") - builder.appendPath(time.toString()) - this.startActivity(Intent(Intent.ACTION_VIEW, builder.build())) - } catch (_: Exception) { - try { - val intent = Intent(this, LauncherActivity::class.java) - intent.addCategory(Intent.CATEGORY_APP_CALENDAR) - this.startActivity(intent) + // Fallback: Open the Calendar app using category + val fallbackIntent = Intent(Intent.ACTION_MAIN).apply { + addCategory(Intent.CATEGORY_APP_CALENDAR) + flags = Intent.FLAG_ACTIVITY_NEW_TASK + } + this.startActivity(fallbackIntent) } catch (e: Exception) { - Log.e("openCalendar", e.toString()) + // Log any error if both methods fail + Log.e("openCalendar", "Failed to open Calendar: ${e.message}") } - } } fun Context.openBatteryManager() {