Reboot opening fixed

faiz_kiosk
faizatflutter 10 months ago
parent 4695e6af86
commit 5427c5e80d

@ -42,3 +42,7 @@ android {
flutter {
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.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<queries>
<intent>
@ -18,7 +19,7 @@
<receiver
android:name=".BootBroadcastReceiver"
android:enabled="true"
android:exported="false">
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
@ -26,6 +27,11 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<service
android:name=".BootForegroundService"
android:exported="true"
android:foregroundServiceType="location" />
<activity
android:name=".MainActivity"
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.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)
}
}
}
}

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

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

@ -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();
}
});
}

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.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"

Loading…
Cancel
Save