Compare commits

...

2 Commits

Author SHA1 Message Date
Ammar Ahmed
c302d6e321 mobile: fix foregroundServiceType 2024-09-18 10:58:41 +05:00
Ammar Ahmed
627e0811ee mobile: fix boot service crash on boot 2024-09-16 15:34:15 +05:00
2 changed files with 27 additions and 12 deletions

View File

@@ -19,6 +19,8 @@
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" tools:node="remove" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<queries>
<intent>
@@ -141,7 +143,7 @@
android:stopWithTask="false" />
<service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" />
<service android:name="com.streetwriters.notesnook.BootTaskService" />
<service android:name="com.streetwriters.notesnook.BootTaskService" android:foregroundServiceType="specialUse" />
<service
android:name=".NotesnookTileService"
@@ -174,7 +176,7 @@
android:resource="@xml/file_viewer_provider_paths" />
</provider>
<receiver android:exported="true" android:name=".BootRecieverService" >
<receiver android:exported="true" android:name=".BootRecieverService">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />

View File

@@ -5,6 +5,7 @@ import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ServiceInfo;
import android.util.Log;
import androidx.core.app.NotificationCompat;
@@ -12,20 +13,22 @@ import androidx.core.app.NotificationCompat;
import com.facebook.react.HeadlessJsTaskService;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.jstasks.HeadlessJsTaskConfig;
import javax.annotation.Nullable;
public class BootTaskService extends HeadlessJsTaskService {
Notification notification;
@Override
protected @Nullable HeadlessJsTaskConfig getTaskConfig(Intent intent) {
Log.d("BootTask", "Task Started");
return new HeadlessJsTaskConfig(
"com.streetwriters.notesnook.BOOT_TASK",
Arguments.createMap(),
30000, // timeout for the task
false // optional: defines whether or not the task is allowed in foreground. Default is false
);
}
protected @Nullable HeadlessJsTaskConfig getTaskConfig(Intent intent) {
Log.d("BootTask", "Task Started");
return new HeadlessJsTaskConfig(
"com.streetwriters.notesnook.BOOT_TASK",
Arguments.createMap(),
30000, // timeout for the task
false // optional: defines whether or not the task is allowed in foreground. Default is false
);
}
@Override
public void onHeadlessJsTaskFinish(int taskId) {
@@ -48,7 +51,17 @@ public class BootTaskService extends HeadlessJsTaskService {
.setContentText("")
.setSmallIcon(R.drawable.ic_stat_name)
.build();
startForeground(1, notification);
if (android.os.Build.VERSION.SDK_INT >= 34) {
this.startForeground(
1,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE);
} else {
this.startForeground(
1,
notification);
}
}
return super.onStartCommand(intent, flags, startId);