Skip to content

Commit

Permalink
Merge pull request #3411 from MerginMaps/tracking-notification
Browse files Browse the repository at this point in the history
Small tracking notification improvements
  • Loading branch information
tomasMizera authored Jun 5, 2024
2 parents 29db4a0 + 645f4b4 commit d2ee626
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 12 deletions.
10 changes: 10 additions & 0 deletions app/android/res/drawable/ic_notification.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
android:viewportWidth="234"
android:viewportHeight="234"
android:width="234dp"
android:height="234dp">
<path
android:pathData="M121.00158 173.91574v28.45121h81.36537V31.633052h-81.36537v28.464542h52.90083V173.91574Zm0 -11.04568V71.129138c23.56394 2.027331 42.04055 21.791647 42.04055 45.870862 0 24.09082 -18.48728 43.8426 -42.04055 45.87006zm-8.00316 39.49689V173.91574H60.084255V60.097594H112.99842V31.633052H31.633052V202.36695Zm0 -39.49689V71.127937C89.428343 73.149 70.945065 92.91625 70.945065 117c0 24.09482 18.494216 43.8506 42.053355 45.87006z"
android:fillType="evenOdd"
android:fillColor="#FFFFFF" />
</vector>
5 changes: 1 addition & 4 deletions app/android/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="notification_title">Mergin Maps is tracking position</string>
<string name="notification_message">Your position is being recorded</string>
<string name="ticker_text">Position tracking</string>
</resources>
</resources>
21 changes: 13 additions & 8 deletions app/android/src/uk/co/lutraconsulting/PositionTrackingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,28 @@ public int onStartCommand( Intent intent, int flags, int startId ) {
NotificationChannel serviceChannel = new NotificationChannel(
CHANNEL_ID,
"Foreground Service Channel",
NotificationManager.IMPORTANCE_HIGH
NotificationManager.IMPORTANCE_LOW
);

NotificationManager manager = getSystemService( NotificationManager.class );
manager.createNotificationChannel( serviceChannel );

// Build notification for position tracking
Intent notificationIntent = new Intent( this, PositionTrackingService.class );
Intent notificationIntent = new Intent( this, InputActivity.class );

PendingIntent pendingIntent = PendingIntent.getActivity( this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE );

Notification notification = new Notification.Builder( this, CHANNEL_ID )
.setContentTitle( getText( R.string.notification_title ) )
.setContentText( getText( R.string.notification_message ) )
.setContentIntent( pendingIntent )
.setTicker( getText( R.string.ticker_text ) )
.build();
Notification.Builder notificationBuilder = new Notification.Builder( this, CHANNEL_ID )
.setSmallIcon( R.drawable.ic_notification )
.setContentTitle( "Tracking in progress" )
.setColor( getResources().getColor( R.color.grassColor ) )
.setContentIntent( pendingIntent );

if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ) { // only Android >= 12
notificationBuilder.setForegroundServiceBehavior( Notification.FOREGROUND_SERVICE_IMMEDIATE );
}

Notification notification = notificationBuilder.build();

startForeground( SERVICE_ID, notification );

Expand Down
42 changes: 42 additions & 0 deletions app/icons/android-foreground-service-notification-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d2ee626

Please sign in to comment.