@@ -48,6 +48,7 @@ type manifestData struct {
4848 Features []string
4949 IconSnip string
5050 AppName string
51+ HasService bool
5152}
5253
5354const (
@@ -67,6 +68,7 @@ const (
6768 <item name="android:statusBarColor">#40000000</item>
6869 </style>
6970</resources>`
71+ foregroundPermission = "android.permission.FOREGROUND_SERVICE"
7072)
7173
7274func init () {
@@ -448,6 +450,7 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
448450 Features : features ,
449451 IconSnip : iconSnip ,
450452 AppName : appName ,
453+ HasService : stringsContains (perms , "foreground" ),
451454 }
452455 tmpl , err := template .New ("test" ).Parse (
453456 `<?xml version="1.0" encoding="utf-8"?>
@@ -470,6 +473,17 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
470473 <category android:name="android.intent.category.LAUNCHER" />
471474 </intent-filter>
472475 </activity>
476+ {{if .HasService}}
477+ <service android:name="org.gioui.GioForegroundService"
478+ android:stopWithTask="true">
479+ <meta-data android:name="org.gioui.ForegroundChannelID"
480+ android:value="gio_foreground" />
481+ <meta-data android:name="org.gioui.ForegroundChannelName"
482+ android:value="GioForeground" />
483+ <meta-data android:name="org.gioui.ForegroundNotificationID"
484+ android:value="0x42424242" />
485+ </service>
486+ {{end}}
473487 </application>
474488</manifest>` )
475489 var manifestBuffer bytes.Buffer
@@ -869,6 +883,15 @@ func getPermissions(ps []string) ([]string, []string) {
869883 return permissions , features
870884}
871885
886+ func stringsContains (strings []string , str string ) bool {
887+ for _ , s := range strings {
888+ if str == s {
889+ return true
890+ }
891+ }
892+ return false
893+ }
894+
872895func latestPlatform (sdk string ) (string , error ) {
873896 allPlats , err := filepath .Glob (filepath .Join (sdk , "platforms" , "android-*" ))
874897 if err != nil {
0 commit comments