From 8de547d61da2871ef719776db787b8985a46c7d0 Mon Sep 17 00:00:00 2001 From: inkeliz Date: Tue, 27 May 2025 04:16:50 +0100 Subject: [PATCH] gogio: [Android] add support for querying apps Previously, it was impossible to identify if a specific app was installed on the user device. It was also impossible to launch a external app from Gio using Intent. Now, you can use `-queries` with a comma separed package names, like `com.another.app`. That allows you to launch Intent to `com.another.app`. Signed-off-by: inkeliz --- gogio/androidbuild.go | 45 ++++++++++++++++++++++++++----------------- gogio/build_info.go | 2 ++ gogio/help.go | 4 ++++ gogio/main.go | 1 + 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/gogio/androidbuild.go b/gogio/androidbuild.go index 03951a0..0b026a9 100644 --- a/gogio/androidbuild.go +++ b/gogio/androidbuild.go @@ -40,15 +40,16 @@ type errWriter struct { var exeSuffix string type manifestData struct { - AppID string - Version Semver - MinSDK int - TargetSDK int - Permissions []string - Features []string - IconSnip string - AppName string - Schemes []string + AppID string + Version Semver + MinSDK int + TargetSDK int + Permissions []string + Features []string + IconSnip string + AppName string + Schemes []string + PackageQueries []string } const ( @@ -435,15 +436,16 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe permissions, features := getPermissions(perms) appName := UppercaseName(bi.name) manifestSrc := manifestData{ - AppID: bi.appID, - Version: bi.version, - MinSDK: minSDK, - TargetSDK: targetSDK, - Permissions: permissions, - Features: features, - IconSnip: iconSnip, - AppName: appName, - Schemes: bi.schemes, + AppID: bi.appID, + Version: bi.version, + MinSDK: minSDK, + TargetSDK: targetSDK, + Permissions: permissions, + Features: features, + IconSnip: iconSnip, + AppName: appName, + Schemes: bi.schemes, + PackageQueries: bi.packageQueries, } tmpl, err := template.New("test").Parse( ` @@ -451,6 +453,13 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe package="{{.AppID}}" android:versionCode="{{.Version.VersionCode}}" android:versionName="{{.Version}}"> + {{if .PackageQueries}} + + {{range .PackageQueries}} + + {{end}} + + {{end}} {{range .Permissions}} {{end}}{{range .Features}} diff --git a/gogio/build_info.go b/gogio/build_info.go index 4125681..cb19066 100644 --- a/gogio/build_info.go +++ b/gogio/build_info.go @@ -32,6 +32,7 @@ type buildInfo struct { notaryPassword string notaryTeamID string schemes []string + packageQueries []string } type Semver struct { @@ -80,6 +81,7 @@ func newBuildInfo(pkgPath string) (*buildInfo, error) { notaryPassword: *notaryPass, notaryTeamID: *notaryTeamID, schemes: getCommaList(*schemes), + packageQueries: getCommaList(*pkgQueries), } return bi, nil } diff --git a/gogio/help.go b/gogio/help.go index 778a559..e7006cd 100644 --- a/gogio/help.go +++ b/gogio/help.go @@ -88,4 +88,8 @@ The -schemes flag specifies a list of comma separated URI schemes that the progr handle. For example, use -schemes yourAppName to receive a app.URLEvent for URIs starting with yourAppName://. It is only supported on Android, iOS, macOS and Windows. On Windows, it will restrict the program to a single instance. + +The -queries flag specifies a list of comma separated package names used to query other apps, +that is useful to launch other apps and verify their presence. For example, use -queries +com.example.otherapp to query the app with that package name. It is only necessary on Android. ` diff --git a/gogio/main.go b/gogio/main.go index c8dd962..bedc17b 100644 --- a/gogio/main.go +++ b/gogio/main.go @@ -42,6 +42,7 @@ var ( notaryPass = flag.String("notarypass", "", "specify app-specific password of the Apple ID to be used for notarization.") notaryTeamID = flag.String("notaryteamid", "", "specify the team id to use for notarization.") schemes = flag.String("schemes", "", "specify a list of comma separated URL schemes that the program accepts") + pkgQueries = flag.String("queries", "", "specify a list of comma separated package names used to query other apps on Android.") ) func main() {