Reboot opening fixed

faiz_kiosk
faizatflutter 10 months ago
parent 4695e6af86
commit 5427c5e80d

@ -42,3 +42,7 @@ android {
flutter { flutter {
source = "../.." source = "../.."
} }
dependencies {
implementation 'androidx.lifecycle:lifecycle-service:2.8.7'
}

@ -3,6 +3,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<queries> <queries>
<intent> <intent>
@ -18,7 +19,7 @@
<receiver <receiver
android:name=".BootBroadcastReceiver" android:name=".BootBroadcastReceiver"
android:enabled="true" android:enabled="true"
android:exported="false"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" /> <action android:name="android.intent.action.QUICKBOOT_POWERON" />
@ -26,6 +27,11 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<service
android:name=".BootForegroundService"
android:exported="true"
android:foregroundServiceType="location" />
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"

@ -0,0 +1,47 @@
package com.example.hmg_qline.hmg_qline
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Intent
import android.os.Build
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.lifecycle.LifecycleService
class BootForegroundService : LifecycleService() {
override fun onCreate() {
super.onCreate()
startForegroundService()
}
private fun startForegroundService() {
val channelId = "boot_service_channel"
if (Build.VERSION.SDK_INT >= 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
}
}

@ -3,17 +3,20 @@ package com.example.hmg_qline.hmg_qline
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import android.util.Log import android.util.Log
class BootBroadcastReceiver : BroadcastReceiver() { class BootBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
Log.d("BootReceiver", "Received intent: ${intent.action}")
Log.d("intent.action Faiz :", "${intent.action}")
if (intent.action == Intent.ACTION_BOOT_COMPLETED || intent.action == "android.intent.action.QUICKBOOT_POWERON") { if (intent.action == Intent.ACTION_BOOT_COMPLETED || intent.action == "android.intent.action.QUICKBOOT_POWERON") {
// Launch the app automatically on boot Log.d("BootReceiver", "Starting BootForegroundService.")
val i = Intent(context, MainActivity::class.java) val serviceIntent = Intent(context, BootForegroundService::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) // Start activity outside of an existing task if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startActivity(i) context.startForegroundService(serviceIntent)
} else {
context.startService(serviceIntent)
}
} }
} }
} }

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig" #include "Generated.xcconfig"

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig" #include "Generated.xcconfig"

@ -192,31 +192,31 @@ class ScreenConfigViewModel extends ChangeNotifier {
final current = DateTime.now(); final current = DateTime.now();
log("Checking Namaz time Locally at ${current.toString()} and ${current.timeZoneName} "); 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(); final namazTime = prayersWidgetModel.fajr!.toFormattedDateTimeFromInt();
nextPrayerToShowWithTime = "${globalConfigurationsModel.fajarText} at $namazTime"; nextPrayerToShowWithTime = "${globalConfigurationsModel.fajarText} at $namazTime";
notifyListeners(); notifyListeners();
return; return;
} }
if (prayersWidgetModel.dhuhr!.toDateTimeFromInt().isAfter(current)) { if (prayersWidgetModel.dhuhr != null && prayersWidgetModel.dhuhr!.toDateTimeFromInt().isAfter(current)) {
final namazTime = prayersWidgetModel.dhuhr!.toFormattedDateTimeFromInt(); final namazTime = prayersWidgetModel.dhuhr!.toFormattedDateTimeFromInt();
nextPrayerToShowWithTime = "${globalConfigurationsModel.dhuhrText} at $namazTime"; nextPrayerToShowWithTime = "${globalConfigurationsModel.dhuhrText} at $namazTime";
notifyListeners(); notifyListeners();
return; return;
} }
if (prayersWidgetModel.asr!.toDateTimeFromInt().isAfter(current)) { if (prayersWidgetModel.asr != null && prayersWidgetModel.asr!.toDateTimeFromInt().isAfter(current)) {
final namazTime = prayersWidgetModel.asr!.toFormattedDateTimeFromInt(); final namazTime = prayersWidgetModel.asr!.toFormattedDateTimeFromInt();
nextPrayerToShowWithTime = "${globalConfigurationsModel.asarText} at $namazTime"; nextPrayerToShowWithTime = "${globalConfigurationsModel.asarText} at $namazTime";
notifyListeners(); notifyListeners();
return; return;
} }
if (prayersWidgetModel.maghrib!.toDateTimeFromInt().isAfter(current)) { if (prayersWidgetModel.maghrib != null && prayersWidgetModel.maghrib!.toDateTimeFromInt().isAfter(current)) {
final namazTime = prayersWidgetModel.maghrib!.toFormattedDateTimeFromInt(); final namazTime = prayersWidgetModel.maghrib!.toFormattedDateTimeFromInt();
nextPrayerToShowWithTime = "${globalConfigurationsModel.maghribText} at $namazTime"; nextPrayerToShowWithTime = "${globalConfigurationsModel.maghribText} at $namazTime";
notifyListeners(); notifyListeners();
return; return;
} }
if (prayersWidgetModel.isha!.toDateTimeFromInt().isAfter(current)) { if (prayersWidgetModel.isha != null && prayersWidgetModel.isha!.toDateTimeFromInt().isAfter(current)) {
final namazTime = prayersWidgetModel.isha!.toFormattedDateTimeFromInt(); final namazTime = prayersWidgetModel.isha!.toFormattedDateTimeFromInt();
nextPrayerToShowWithTime = "${globalConfigurationsModel.ishaText} at $namazTime"; nextPrayerToShowWithTime = "${globalConfigurationsModel.ishaText} at $namazTime";
notifyListeners(); notifyListeners();
@ -265,7 +265,10 @@ class ScreenConfigViewModel extends ChangeNotifier {
await getRssFeedDetailsFromServer(); await getRssFeedDetailsFromServer();
} }
} }
getNextPrayerToShow();
if (globalConfigurationsModel.isPrayerTimeReq) {
getNextPrayerToShow();
}
}); });
} }

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig"

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig"

Loading…
Cancel
Save