Skip to content

ALEX5402/Haptify-android

Repository files navigation

Haptify

image image

Convert music and dialogues playing on your device into expressive haptic feedback.

Haptify captures system playback (not the microphone) on Android 10+ and generates vibrations that follow the audio energy and voice onsets in real time. It runs as a foreground service with an optional Quick Settings tile for one‑tap control.

Features

  • Real‑time playback capture (AudioPlayback Capture, Android 10+)
  • Voice/beat‑focused haptic algorithm with noise‑gate and adaptive thresholds
  • Foreground service with status notification (configurable: active or silent)
  • Quick Settings tile to start/stop (launches screen‑capture consent)
  • Onboarding explaining permissions and how to use
  • Simple, modern Material 3 UI (dark/light)

How it works (privacy)

  • Haptify uses Android’s AudioPlayback Capture API via MediaProjection to read PCM from other apps’ audio output. This requires the RECORD_AUDIO permission and a one‑time screen capture consent sheet from the system.
  • Despite the permission name, Haptify does not open the physical microphone. Android shows the same indicator for playback capture and mic use.
  • Some apps can opt out from capture (e.g., DRM or explicit policy). In those cases, Haptify cannot access their audio.

Requirements

  • Android Studio Hedgehog/Koala or newer
  • Android 10 (API 29) or later
  • minSdk 24, targetSdk 36

Build & Run

  1. Open the project in Android Studio.
  2. Sync Gradle and build the app module.
  3. Run on a physical device (recommended for vibration testing).

Or via Gradle:

./gradlew assembleDebug

First‑time setup

  1. Launch Haptify and complete the onboarding.
  2. Tap Start Service.
  3. Approve the system screen‑capture consent dialog.
  4. Play music or video in any app and feel the haptics.

Tip: Add the Haptify Quick Settings tile for fast toggling (pull down QS → edit/pencil → drag “Haptify”).

Controls

  • Start/Stop Service: Runs the foreground service for capture and haptics.
  • Show status notification: Switch between a visible “Active” channel and a low‑priority “Silent” channel. Android requires a persistent notification for foreground services; the silent channel minimizes its visibility.

Troubleshooting

  • “Media projections require a foreground service …”
    • Use the latest build. On Android 14+, the service starts with mediaProjection | mediaPlayback foreground types.
  • “AudioRecord could not create record track” or “startRecording on uninitialized AudioRecord”
    • The source app may block capture (DRM/policy). Try a different player or local files.
    • Ensure both RECORD_AUDIO and the screen‑capture consent are granted.
  • No haptics when idle
    • A noise gate prevents vibration without playback; start audio and adjust volume.

Project structure

  • app/src/main/java/com/audio/haptify/service/HapticFeedbackService.kt — MediaProjection + AudioPlaybackCapture; haptic logic
  • app/src/main/java/com/audio/haptify/tile/HaptifyTileService.kt — Quick Settings tile (launches consent)
  • app/src/main/java/com/audio/haptify/MainActivity.kt — UI, onboarding, settings toggle
  • app/src/main/java/com/audio/haptify/ui/Onboarding.kt — theme‑aware onboarding
  • app/src/main/java/com/audio/haptify/prefs/Prefs.kt — preferences wrapper

Permissions

  • RECORD_AUDIO — Needed by Android to capture playback (not the mic input).
  • FOREGROUND_SERVICE, FOREGROUND_SERVICE_MEDIA_PROJECTION, FOREGROUND_SERVICE_MEDIA_PLAYBACK — Foreground service requirements.
  • POST_NOTIFICATIONS (Android 13+) — To display the required notification.

Contributing

PRs welcome. Please include device model/Android version when changing capture logic.

License

TBD. Open an issue if you need a specific license (MIT/Apache‑2.0, etc.).