You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+82Lines changed: 82 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1627,6 +1627,88 @@ bridging. Writing CGo from scratch duplicates this work and lacks the
1627
1627
automated test coverage this project maintains.
1628
1628
-->
1629
1629
1630
+
## Interoperability with standard packages
1631
+
1632
+
All handle types expose `UintPtr() uintptr` and `NewXFromUintPtr(uintptr)` methods alongside the existing `Pointer()`/`NewXFromPointer()` pair. This enables interop with Go packages that represent native Android handles as `uintptr` — including `golang.org/x/mobile`, `gioui.org`, and `github.com/xlab/android-go`.
1633
+
1634
+
For generic code, all handles satisfy the `handle.NativeHandle` interface:
1635
+
1636
+
```go
1637
+
import "github.com/AndroidGoLab/ndk/handle"
1638
+
1639
+
func logHandle(h handle.NativeHandle) {
1640
+
log.Printf("native handle: 0x%x", h.UintPtr())
1641
+
}
1642
+
```
1643
+
1644
+
EGL types (`EGLDisplay`, `EGLContext`, etc.) are `unsafe.Pointer` aliases and use free functions instead: `egl.EGLDisplayToUintPtr(d)` / `egl.EGLDisplayFromUintPtr(p)`.
1645
+
1646
+
<details>
1647
+
<summary>gomobile bind</summary>
1648
+
1649
+
`gomobile bind` does not support `unsafe.Pointer` or `uintptr` in exported APIs. Transport native handles as `int64` (Java `long`) and convert inside Go:
1650
+
1651
+
```go
1652
+
package sensorbridge
1653
+
1654
+
import"github.com/AndroidGoLab/ndk/sensor"
1655
+
1656
+
// Bridge wraps an ASensorManager for cross-language use.
1657
+
// Unexported fields are invisible to Java/Kotlin.
1658
+
typeBridgestruct {
1659
+
mgr *sensor.Manager
1660
+
}
1661
+
1662
+
// NewBridge creates a Bridge from a raw ASensorManager* passed as int64
1663
+
// (Java long). gomobile bind does not support unsafe.Pointer or uintptr,
1664
+
// so native handles must be transported as int64.
0 commit comments