@@ -49,6 +49,7 @@ type manifestData struct {
4949 Features []string
5050 IconSnip string
5151 AppName string
52+ HasService bool
5253}
5354
5455const (
@@ -68,6 +69,7 @@ const (
6869 <item name="android:statusBarColor">#40000000</item>
6970 </style>
7071</resources>`
72+ foregroundPermission = "android.permission.FOREGROUND_SERVICE"
7173)
7274
7375func init () {
@@ -446,6 +448,7 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
446448 Features : features ,
447449 IconSnip : iconSnip ,
448450 AppName : appName ,
451+ HasService : stringsContains (permissions , foregroundPermission ),
449452 }
450453 tmpl , err := template .New ("test" ).Parse (
451454 `<?xml version="1.0" encoding="utf-8"?>
@@ -468,6 +471,19 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
468471 <category android:name="android.intent.category.LAUNCHER" />
469472 </intent-filter>
470473 </activity>
474+ {{if .HasService}}
475+ <service android:name="org.gioui.GioForegroundService"
476+ android:stopWithTask="true">
477+ <meta-data android:name="org.gioui.ForegroundChannelID"
478+ android:value="gio_foreground" />
479+ <meta-data android:name="org.gioui.ForegroundChannelName"
480+ android:value="GioForeground" />
481+ <meta-data android:name="org.gioui.ForegroundChannelDesc"
482+ android:value="" />
483+ <meta-data android:name="org.gioui.ForegroundNotificationID"
484+ android:value="0x42424242" />
485+ </service>
486+ {{end}}
471487 </application>
472488</manifest>` )
473489 var manifestBuffer bytes.Buffer
@@ -865,6 +881,15 @@ func getPermissions(ps []string) ([]string, []string) {
865881 return permissions , features
866882}
867883
884+ func stringsContains (strings []string , str string ) bool {
885+ for _ , s := range strings {
886+ if str == s {
887+ return true
888+ }
889+ }
890+ return false
891+ }
892+
868893func latestPlatform (sdk string ) (string , error ) {
869894 allPlats , err := filepath .Glob (filepath .Join (sdk , "platforms" , "android-*" ))
870895 if err != nil {
0 commit comments