Skip to content

Commit

Permalink
Update to background service operation (#3374)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesSmartCell authored Apr 19, 2024
1 parent 26e15c6 commit 1f766ec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>

<uses-feature
Expand Down Expand Up @@ -124,7 +125,7 @@
<service
android:name=".service.WalletConnectV2Service"
android:enabled="true"
android:foregroundServiceType="shortService"
android:foregroundServiceType="dataSync"
android:exported="false">
</service>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.content.pm.ServiceInfo;
import android.os.Build;
import android.os.IBinder;

Expand Down Expand Up @@ -59,12 +60,23 @@ private void createNotificationChannel()
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
@RequiresApi(api = Build.VERSION_CODES.O)

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
createNotificationChannel();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
createNotificationChannel();
}
Notification notification = createNotification();
startForeground(1, notification);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
{
startForeground(startId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
}
else
{
startForeground(startId, notification);
}

return START_STICKY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ServiceInfo;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
Expand Down

0 comments on commit 1f766ec

Please sign in to comment.