|
| 1 | +# Android Platform Implementation |
| 2 | + |
| 3 | +This directory contains Android-specific implementations of the nativeapi library. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The Android implementation uses the Android NDK to provide access to native system APIs. Due to Android's unique application model, some desktop concepts are mapped differently: |
| 8 | + |
| 9 | +- **Windows** → Activities/Views (`ANativeWindow`) |
| 10 | +- **Menus** → Context menus or ActionBar menus |
| 11 | +- **Tray Icons** → System notifications |
| 12 | +- **Display Management** → Display Manager API |
| 13 | +- **Keyboard Monitoring** → Accessibility Services |
| 14 | + |
| 15 | +## Files |
| 16 | + |
| 17 | +- `window_android.cpp` - Window management using `ANativeWindow` |
| 18 | +- `window_manager_android.cpp` - Window manager for Activity lifecycle |
| 19 | +- `display_android.cpp` - Display information (stub) |
| 20 | +- `display_manager_android.cpp` - Display manager (stub) |
| 21 | +- `menu_android.cpp` - Menu implementation (stub) |
| 22 | +- `tray_icon_android.cpp` - Tray icon using notifications (stub) |
| 23 | +- `tray_manager_android.cpp` - Tray manager (stub) |
| 24 | +- `keyboard_monitor_android.cpp` - Keyboard monitoring via AccessibilityService (stub) |
| 25 | +- `accessibility_manager_android.cpp` - Accessibility manager (stub) |
| 26 | +- `application_android.cpp` - Application lifecycle (stub) |
| 27 | +- `image_android.cpp` - Image loading (stub) |
| 28 | + |
| 29 | +## Building |
| 30 | + |
| 31 | +These files are automatically included when building with the Android NDK: |
| 32 | + |
| 33 | +```bash |
| 34 | +cmake -DCMAKE_SYSTEM_NAME=Android \ |
| 35 | + -DCMAKE_ANDROID_NDK=/path/to/android-ndk \ |
| 36 | + .. |
| 37 | +``` |
| 38 | + |
| 39 | +## Android NDK Requirements |
| 40 | + |
| 41 | +- Android NDK r21 or later |
| 42 | +- Minimum Android SDK: API level 24 (Android 7.0) |
| 43 | +- Recommended: API level 29+ (Android 10.0+) |
| 44 | + |
| 45 | +## Key Differences from Desktop |
| 46 | + |
| 47 | +### Window Management |
| 48 | + |
| 49 | +Android uses `ANativeWindow` instead of platform-specific window handles: |
| 50 | + |
| 51 | +```cpp |
| 52 | +// Desktop: HWND (Windows), NSWindow* (macOS), GdkWindow* (Linux) |
| 53 | +// Android: ANativeWindow* |
| 54 | + |
| 55 | +void* Window::GetNativeObjectInternal() const { |
| 56 | + return static_cast<void*>(pimpl_->native_window_); |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +### Activity Lifecycle |
| 61 | + |
| 62 | +Windows in Android are created and managed through the Activity lifecycle. Window creation happens automatically when the Activity creates a native window surface. |
| 63 | + |
| 64 | +### Logging |
| 65 | + |
| 66 | +Android uses the logging API instead of standard output: |
| 67 | + |
| 68 | +```cpp |
| 69 | +#include <android/log.h> |
| 70 | + |
| 71 | +#define LOG_TAG "NativeApi" |
| 72 | +#define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) |
| 73 | +``` |
| 74 | +
|
| 75 | +## Implementation Status |
| 76 | +
|
| 77 | +| Component | Status | Notes | |
| 78 | +|-----------|--------|-------| |
| 79 | +| Window | ✅ Implemented | Uses ANativeWindow API | |
| 80 | +| Window Manager | ✅ Implemented | Activity lifecycle integration | |
| 81 | +| Display | ⚠️ Stub | Basic implementation | |
| 82 | +| Display Manager | ⚠️ Stub | Basic implementation | |
| 83 | +| Menu | ⚠️ Stub | Needs Context menu integration | |
| 84 | +| Tray Icon | ⚠️ Stub | Needs Notification API | |
| 85 | +| Tray Manager | ⚠️ Stub | Needs Notification API | |
| 86 | +| Keyboard Monitor | ⚠️ Stub | Needs AccessibilityService | |
| 87 | +| Accessibility Manager | ⚠️ Stub | Needs Android permissions | |
| 88 | +| Application | ⚠️ Stub | Basic lifecycle | |
| 89 | +| Image | ⚠️ Stub | Needs Bitmap loading | |
| 90 | +
|
| 91 | +## See Also |
| 92 | +
|
| 93 | +- [Android NDK Documentation](https://developer.android.com/ndk) |
| 94 | +- [ANativeWindow API](https://developer.android.com/ndk/reference/group/native-activity#anativewindow) |
| 95 | +- [docs/ANDROID.md](../../../docs/ANDROID.md) - User-facing Android documentation |
| 96 | +
|
0 commit comments