Skip to content

Commit d7a62aa

Browse files
Fix: Testing a fix for calendar apps
1 parent 91cea2f commit d7a62aa

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

app/src/main/java/com/github/droidworksstudio/common/ContextExtensions.kt

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -304,22 +304,16 @@ fun Context.launchClock() {
304304

305305
fun Context.launchCalendar() {
306306
try {
307-
val cal: Calendar = Calendar.getInstance()
308-
cal.time = Date()
309-
val time = cal.time.time
310-
val builder: Uri.Builder = CalendarContract.CONTENT_URI.buildUpon()
311-
builder.appendPath("time")
312-
builder.appendPath(time.toString())
313-
this.startActivity(Intent(Intent.ACTION_VIEW, builder.build()))
314-
} catch (_: Exception) {
315-
try {
316-
val intent = Intent(this, LauncherActivity::class.java)
317-
intent.addCategory(Intent.CATEGORY_APP_CALENDAR)
318-
this.startActivity(intent)
307+
// Fallback: Open the Calendar app using category
308+
val fallbackIntent = Intent(Intent.ACTION_MAIN).apply {
309+
addCategory(Intent.CATEGORY_APP_CALENDAR)
310+
flags = Intent.FLAG_ACTIVITY_NEW_TASK
311+
}
312+
this.startActivity(fallbackIntent)
319313
} catch (e: Exception) {
320-
Log.e("openCalendar", e.toString())
314+
// Log any error if both methods fail
315+
Log.e("openCalendar", "Failed to open Calendar: ${e.message}")
321316
}
322-
}
323317
}
324318

325319
fun Context.openBatteryManager() {

0 commit comments

Comments
 (0)