capacitor-android

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Capacitor & Android Native Bridge Skill

Capacitor & Android Native Bridge 技能

This skill enables the assistant to handle the complex interaction between the Web layer (React) and the Native layer (Java/Android) specifically for background tracking.
该技能可让助手处理Web层(React)与原生层(Java/Android)之间针对后台追踪的复杂交互。

Knowledge Areas

知识领域

1. Android Foreground Services

1. Android Foreground Services

  • Lifecycle Management: Start/stop/restart logic for
    LocationTrackingService.java
    .
  • Notifications: Maintaining persistent notifications required by Android for foreground tasks.
  • Boot Persistence: Implementing
    BOOT_COMPLETED
    receivers to restart tracking on device reboot.
  • 生命周期管理:
    LocationTrackingService.java
    的启动/停止/重启逻辑。
  • 通知: 维护Android前台任务所需的持久化通知。
  • 开机持久化: 实现
    BOOT_COMPLETED
    接收器,在设备重启后重新启动追踪。

2. Battery & Power Management

2. Battery & Power Management

  • Wakelocks: Smart management of
    PARTIAL_WAKE_LOCK
    to balance tracking consistency with battery life.
  • Doze Mode: Using
    AlarmManager.setExactAndAllowWhileIdle()
    for reliable 60s intervals.
  • Optimization Whitelisting: Handling
    REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
    .
  • 唤醒锁: 智能管理
    PARTIAL_WAKE_LOCK
    ,平衡追踪一致性与电池续航。
  • 休眠模式: 使用
    AlarmManager.setExactAndAllowWhileIdle()
    实现可靠的60秒间隔。
  • 优化白名单: 处理
    REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
    请求。

3. Capacitor Plugin Development

3. Capacitor Plugin Development

  • Bridge Communication: Efficiently passing data between
    ProTrackingPlugin.java
    and React.
  • Native-to-Web Events: Using
    notifyListeners
    for real-time status updates in the UI.
  • 桥接通信:
    ProTrackingPlugin.java
    与React之间高效传递数据。
  • 原生到Web事件: 使用
    notifyListeners
    在UI中实现实时状态更新。

4. Background Geolocation

4. Background Geolocation

  • Providers: Fine-tuning
    FusedLocationProviderClient
    settings (Priority, Interval, FastestInterval).
  • Permissions: Managing granular location permissions (Fine, Background) and notification permissions.
  • 位置提供商: 微调
    FusedLocationProviderClient
    的设置(优先级、间隔、最快间隔)。
  • 权限管理: 管理精细化位置权限(精确位置、后台位置)以及通知权限。

Guidelines for Responses

响应指南

  • When modifying Java code, ensure Thread Safety (especially for network calls and location updates).
  • Always recommend releasing Wakelocks when the GPS fix is obtained or if a timeout occurs.
  • Suggest exponential backoff for failed HTTP requests in
    LocationApiClient.java
    .
  • Keep in mind Android 14+ requirements (Foreground Service Types).
  • 修改Java代码时,确保线程安全(尤其是网络调用和位置更新场景)。
  • 建议在获取到GPS定位或发生超时后,始终释放唤醒锁
  • 建议为
    LocationApiClient.java
    中的失败HTTP请求实现指数退避策略
  • 注意Android 14+的要求(前台服务类型)。