Skip to content

fix(android): Android 7 (API 25) compatibility — prevent launch and service crashes - #86

Open
LeaderOnePro wants to merge 4 commits into
sipeed:mainfrom
LeaderOnePro:fix/android7-api25-compat
Open

fix(android): Android 7 (API 25) compatibility — prevent launch and service crashes#86
LeaderOnePro wants to merge 4 commits into
sipeed:mainfrom
LeaderOnePro:fix/android7-api25-compat

Conversation

@LeaderOnePro

Copy link
Copy Markdown

Summary

Fixes three crashes that prevent the app from running on Android 7.x (API 25) devices:

  1. App crashes on launchandroid.app.NotificationChannel does not exist on API 25.
  2. App crashes when tapping LAUNCH SERVICEContext.startForegroundService() was added in API 26.
  3. App crashes when tapping STOP SERVICEProcess.isAlive() was added in API 26.

Additionally, the service panics with mkdir ... permission denied because WRITE_EXTERNAL_STORAGE was never requested at runtime on API 23-29.

Changes

File Fix
MainActivity.kt Request WRITE_EXTERNAL_STORAGE / READ_PHONE_STATE at runtime on API 23-29
PicoClawService.kt Use ContextCompat.startForegroundService() + thread.isAlive() instead of Process.isAlive()
PicoClawApp.kt Guard NotificationChannel creation behind Build.VERSION.SDK_INT >= O

Verification

Tested on Honor 5A running LineageOS Android 7.1.2 (API 25):

  • App launches without crash ✅
  • Permission dialog shown on first launch ✅
  • LAUNCH SERVICE starts the web server on port 18800 ✅
  • STOP SERVICE stops cleanly (exit code 0) ✅

On API 26+ devices all three codepaths behave identically to before (no regression).

LeaderOnePro and others added 3 commits July 21, 2026 02:44
On API 23-29 (Android 6-9), WRITE_EXTERNAL_STORAGE and READ_PHONE_STATE
are dangerous permissions that must be granted at runtime.  Without this
the service panicked with "mkdir ... permission denied" when trying to
create its workspace in shared storage.

Prompts the user from MainActivity.onCreate on first launch.  API < 23
(install-time grants) and API 30+ (MANAGE_EXTERNAL_STORAGE path, already
handled in onResume) are skipped.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… equivalents

Crash 1 — on service START (on API < 26):
  java.lang.NoSuchMethodError: startForegroundService  (added in API 26)
  Fix: ContextCompat.startForegroundService (falls back to startService)

Crash 2 — on service STOP (on API < 26):
  java.lang.NoSuchMethodError: Process.isAlive  (added in API 26)
  Fix: thread.isAlive() — logically equivalent since the wait-thread
       exits exactly when the process does, and available since API 1.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
App crashed on launch on API 25 (Android 7.x) with:
  java.lang.NoClassDefFoundError: android.app.NotificationChannel
NotificationChannel was added in API 26 — the unconditional reference
prevented theApplication from even finishing onCreate.

Skips channel creation on API < 26; the foreground service still works,
it just uses the default notification style on those older devices.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 20, 2026 18:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

… Android 7

On API 25 (Android 7.x) the Go binary's -public flag is not detected by
flag.Visit, causing effectivePublic to fall back to the config default
(false) and the service binds to 127.0.0.1 only.

Switch to -host 0.0.0.0 which takes the exact-binding code path and
binds to all interfaces reliably on every API level.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants