forked from organicmaps/organicmaps
[android-auto] Make AA background service
Signed-off-by: Andrew Shkrob <andrew.shkrob.social@yandex.by>
This commit is contained in:
parent
0e38f132cd
commit
4b889f5b72
3 changed files with 6 additions and 30 deletions
|
@ -454,14 +454,16 @@
|
|||
<service
|
||||
android:name="app.organicmaps.car.CarAppService"
|
||||
android:exported="true"
|
||||
android:foregroundServiceType="specialUse"
|
||||
tools:ignore="ExportedService">
|
||||
<intent-filter>
|
||||
<action android:name="androidx.car.app.CarAppService" />
|
||||
<category android:name="androidx.car.app.category.NAVIGATION" />
|
||||
</intent-filter>
|
||||
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
|
||||
android:value="@string/android_auto_fgs_explanation_for_special_use"/>
|
||||
<intent-filter>
|
||||
<action android:name="androidx.car.app.action.NAVIGATE" />
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:scheme="geo" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<service
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package app.organicmaps.car;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
@ -23,7 +22,6 @@ import androidx.lifecycle.LifecycleOwner;
|
|||
import app.organicmaps.BuildConfig;
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.api.Const;
|
||||
import app.organicmaps.routing.NavigationService;
|
||||
|
||||
public final class CarAppService extends androidx.car.app.CarAppService
|
||||
{
|
||||
|
@ -53,20 +51,7 @@ public final class CarAppService extends androidx.car.app.CarAppService
|
|||
public Session onCreateSession(@Nullable SessionInfo sessionInfo)
|
||||
{
|
||||
createNotificationChannel();
|
||||
startForeground(NOTIFICATION_ID, getNotification());
|
||||
final CarAppSession carAppSession = new CarAppSession(sessionInfo);
|
||||
carAppSession.getLifecycle().addObserver(new DefaultLifecycleObserver()
|
||||
{
|
||||
@Override
|
||||
public void onDestroy(@NonNull LifecycleOwner owner)
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
stopForeground(STOP_FOREGROUND_REMOVE);
|
||||
else
|
||||
stopForeground(true);
|
||||
}
|
||||
});
|
||||
return carAppSession;
|
||||
return new CarAppSession(sessionInfo);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -104,13 +89,4 @@ public final class CarAppService extends androidx.car.app.CarAppService
|
|||
.build();
|
||||
notificationManager.createNotificationChannel(notificationChannel);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Notification getNotification()
|
||||
{
|
||||
return NavigationService.getNotificationBuilder(this)
|
||||
.setChannelId(ANDROID_AUTO_NOTIFICATION_CHANNEL_ID)
|
||||
.setContentTitle(getString(R.string.aa_connected_to_car_notification_title))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,4 @@
|
|||
<string name="placepage_behavior" translatable="false">com.google.android.material.bottomsheet.BottomSheetBehavior</string>
|
||||
|
||||
<string name="car_notification_channel_name" translatable="false">Car</string>
|
||||
|
||||
<string name="android_auto_fgs_explanation_for_special_use" translatable="false">Since Android 14, every Foreground Service must have a type. There is no specific service type for Android Auto.</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Reference in a new issue