-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect Android API level if possible
- Loading branch information
Showing
3 changed files
with
55 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//go:build !(android && cgo) | ||
|
||
package anet | ||
|
||
func androidDeviceApiLevel() int { | ||
return -1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//go:build android && cgo | ||
|
||
package anet | ||
|
||
// #include <android/api-level.h> | ||
import "C" | ||
|
||
import "sync" | ||
|
||
var ( | ||
apiLevel int | ||
once sync.Once | ||
) | ||
|
||
// Returns the API level of the device we're actually running on, or -1 on failure. | ||
// The returned value is equivalent to the Java Build.VERSION.SDK_INT API. | ||
func androidDeviceApiLevel() int { | ||
once.Do(func() { | ||
apiLevel = int(C.android_get_device_api_level()) | ||
}) | ||
|
||
return apiLevel | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters