From 5427c5e80d87e3ad8a4408aa704107e37e7b835a Mon Sep 17 00:00:00 2001 From: faizatflutter Date: Sun, 12 Jan 2025 11:56:07 +0300 Subject: [PATCH] Reboot opening fixed --- android/app/build.gradle | 4 ++ android/app/src/main/AndroidManifest.xml | 8 +++- .../hmg_qline/BootForegroundService.kt | 47 +++++++++++++++++++ .../hmg_qline/hmg_qline/BootReceiver.kt | 15 +++--- ios/Flutter/Debug.xcconfig | 1 + ios/Flutter/Release.xcconfig | 1 + lib/view_models/screen_config_view_model.dart | 15 +++--- macos/Flutter/Flutter-Debug.xcconfig | 1 + macos/Flutter/Flutter-Release.xcconfig | 1 + 9 files changed, 80 insertions(+), 13 deletions(-) create mode 100644 android/app/src/main/kotlin/com/example/hmg_qline/hmg_qline/BootForegroundService.kt diff --git a/android/app/build.gradle b/android/app/build.gradle index b8bdf34..f055702 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -42,3 +42,7 @@ android { flutter { source = "../.." } + +dependencies { + implementation 'androidx.lifecycle:lifecycle-service:2.8.7' +} diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index b4650a9..d519056 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ + @@ -18,7 +19,7 @@ + android:exported="true"> @@ -26,6 +27,11 @@ + + = Build.VERSION_CODES.O) { + val channel = NotificationChannel( + channelId, + "Boot Service Channel", + NotificationManager.IMPORTANCE_DEFAULT + ) + val manager = getSystemService(NotificationManager::class.java) + manager?.createNotificationChannel(channel) + } + + val notification: Notification = NotificationCompat.Builder(this, channelId) + .setContentTitle("QLine App") + .setContentText("Launching application...") + .setSmallIcon(R.mipmap.ic_launcher) + .build() + + startForeground(1, notification) + + // Launch MainActivity + Log.d("BootForegroundService", "Starting MainActivity") + val intent = Intent(this, MainActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + startActivity(intent) + + stopSelf() // Stop the service after launching the app + } +} \ No newline at end of file diff --git a/android/app/src/main/kotlin/com/example/hmg_qline/hmg_qline/BootReceiver.kt b/android/app/src/main/kotlin/com/example/hmg_qline/hmg_qline/BootReceiver.kt index 11a61da..f185b37 100644 --- a/android/app/src/main/kotlin/com/example/hmg_qline/hmg_qline/BootReceiver.kt +++ b/android/app/src/main/kotlin/com/example/hmg_qline/hmg_qline/BootReceiver.kt @@ -3,17 +3,20 @@ package com.example.hmg_qline.hmg_qline import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.os.Build import android.util.Log class BootBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { - - Log.d("intent.action Faiz :", "${intent.action}") + Log.d("BootReceiver", "Received intent: ${intent.action}") if (intent.action == Intent.ACTION_BOOT_COMPLETED || intent.action == "android.intent.action.QUICKBOOT_POWERON") { - // Launch the app automatically on boot - val i = Intent(context, MainActivity::class.java) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) // Start activity outside of an existing task - context.startActivity(i) + Log.d("BootReceiver", "Starting BootForegroundService.") + val serviceIntent = Intent(context, BootForegroundService::class.java) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + context.startForegroundService(serviceIntent) + } else { + context.startService(serviceIntent) + } } } } \ No newline at end of file diff --git a/ios/Flutter/Debug.xcconfig b/ios/Flutter/Debug.xcconfig index 592ceee..ec97fc6 100644 --- a/ios/Flutter/Debug.xcconfig +++ b/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/ios/Flutter/Release.xcconfig b/ios/Flutter/Release.xcconfig index 592ceee..c4855bf 100644 --- a/ios/Flutter/Release.xcconfig +++ b/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/lib/view_models/screen_config_view_model.dart b/lib/view_models/screen_config_view_model.dart index e2b8338..50a54d7 100644 --- a/lib/view_models/screen_config_view_model.dart +++ b/lib/view_models/screen_config_view_model.dart @@ -192,31 +192,31 @@ class ScreenConfigViewModel extends ChangeNotifier { final current = DateTime.now(); log("Checking Namaz time Locally at ${current.toString()} and ${current.timeZoneName} "); - if (prayersWidgetModel.fajr!.toDateTimeFromInt().isAfter(current)) { + if (prayersWidgetModel.fajr != null && prayersWidgetModel.fajr!.toDateTimeFromInt().isAfter(current)) { final namazTime = prayersWidgetModel.fajr!.toFormattedDateTimeFromInt(); nextPrayerToShowWithTime = "${globalConfigurationsModel.fajarText} at $namazTime"; notifyListeners(); return; } - if (prayersWidgetModel.dhuhr!.toDateTimeFromInt().isAfter(current)) { + if (prayersWidgetModel.dhuhr != null && prayersWidgetModel.dhuhr!.toDateTimeFromInt().isAfter(current)) { final namazTime = prayersWidgetModel.dhuhr!.toFormattedDateTimeFromInt(); nextPrayerToShowWithTime = "${globalConfigurationsModel.dhuhrText} at $namazTime"; notifyListeners(); return; } - if (prayersWidgetModel.asr!.toDateTimeFromInt().isAfter(current)) { + if (prayersWidgetModel.asr != null && prayersWidgetModel.asr!.toDateTimeFromInt().isAfter(current)) { final namazTime = prayersWidgetModel.asr!.toFormattedDateTimeFromInt(); nextPrayerToShowWithTime = "${globalConfigurationsModel.asarText} at $namazTime"; notifyListeners(); return; } - if (prayersWidgetModel.maghrib!.toDateTimeFromInt().isAfter(current)) { + if (prayersWidgetModel.maghrib != null && prayersWidgetModel.maghrib!.toDateTimeFromInt().isAfter(current)) { final namazTime = prayersWidgetModel.maghrib!.toFormattedDateTimeFromInt(); nextPrayerToShowWithTime = "${globalConfigurationsModel.maghribText} at $namazTime"; notifyListeners(); return; } - if (prayersWidgetModel.isha!.toDateTimeFromInt().isAfter(current)) { + if (prayersWidgetModel.isha != null && prayersWidgetModel.isha!.toDateTimeFromInt().isAfter(current)) { final namazTime = prayersWidgetModel.isha!.toFormattedDateTimeFromInt(); nextPrayerToShowWithTime = "${globalConfigurationsModel.ishaText} at $namazTime"; notifyListeners(); @@ -265,7 +265,10 @@ class ScreenConfigViewModel extends ChangeNotifier { await getRssFeedDetailsFromServer(); } } - getNextPrayerToShow(); + + if (globalConfigurationsModel.isPrayerTimeReq) { + getNextPrayerToShow(); + } }); } diff --git a/macos/Flutter/Flutter-Debug.xcconfig b/macos/Flutter/Flutter-Debug.xcconfig index c2efd0b..4b81f9b 100644 --- a/macos/Flutter/Flutter-Debug.xcconfig +++ b/macos/Flutter/Flutter-Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig" diff --git a/macos/Flutter/Flutter-Release.xcconfig b/macos/Flutter/Flutter-Release.xcconfig index c2efd0b..5caa9d1 100644 --- a/macos/Flutter/Flutter-Release.xcconfig +++ b/macos/Flutter/Flutter-Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig"