mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-28 14:08:16 +08:00
Android 本地加速改为 前台服务 & 修复 PendingIntent 在 Android 12+ 上的异常 & 主活动增加参数打开对应的子页
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using System.Application.Services.Native;
|
||||
using NativeService = System.Application.Services.Native.IServiceBase;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace System
|
||||
{
|
||||
partial class ContextExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 启动或关闭前台服务
|
||||
/// </summary>
|
||||
/// <typeparam name="TService"></typeparam>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="startOrStop"></param>
|
||||
public static void CallForegroundService<TService>(this Context context, bool startOrStop) where TService : Service, IServiceBase
|
||||
{
|
||||
Intent intent = new(context, typeof(TService));
|
||||
intent.SetAction(startOrStop ? NativeService.START : NativeService.STOP);
|
||||
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
|
||||
{
|
||||
context.StartForegroundService(intent);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.StartService(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user