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 <inkeliz@inkeliz.com>
This commit is contained in:
inkeliz
2025-05-27 04:16:50 +01:00
committed by Elias Naur
parent 048614c60e
commit 8de547d61d
4 changed files with 34 additions and 18 deletions
+27 -18
View File
@@ -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(
`<?xml version="1.0" encoding="utf-8"?>
@@ -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}}
<queries>
{{range .PackageQueries}}
<package android:name="{{.}}" />
{{end}}
</queries>
{{end}}
<uses-sdk android:minSdkVersion="{{.MinSDK}}" android:targetSdkVersion="{{.TargetSDK}}" />
{{range .Permissions}} <uses-permission android:name="{{.}}"/>
{{end}}{{range .Features}} <uses-feature android:{{.}} android:required="false"/>
+2
View File
@@ -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
}
+4
View File
@@ -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.
`
+1
View File
@@ -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() {