https://github.com/hyunjinno/foregroundaudiorecorder
A library for audio recording at foreground.
https://github.com/hyunjinno/foregroundaudiorecorder
android foreground-service jitpack recorder
Last synced: about 1 month ago
JSON representation
A library for audio recording at foreground.
- Host: GitHub
- URL: https://github.com/hyunjinno/foregroundaudiorecorder
- Owner: HyunJinNo
- Created: 2023-08-18T04:42:16.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-12T03:22:06.000Z (over 2 years ago)
- Last Synced: 2025-10-20T07:55:42.967Z (8 months ago)
- Topics: android, foreground-service, jitpack, recorder
- Language: Kotlin
- Homepage:
- Size: 390 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ForegroundAudioRecorder
A library for audio recording at foreground.
[](https://jitpack.io/#HyunJinNo/ForegroundAudioRecorder)
## Index
[1. Examples](#example)
[2. Gradle Setup](#gradle-setup)
[3. How to use](#how-to-use)
## Example



## Gradle Setup
To get this library into your build:
#### Step 1. Add the JitPack repository to your build file.
Add it in your settings.gradle at the end of repositories:
```gradle
repositories {
...
maven { url 'https://jitpack.io' }
}
```
#### Step 2. Add the dependency.
Add it in your build.gradle (:app):
```gradle
dependencies {
...
implementation 'com.github.HyunJinNo:ForegroundAudioRecorder:0.0:3'
}
```
## How to use
#### Step 1. Add the following permissions to your AndroidManifest.xml.
```xml
...
...
```
#### Step 2. Request permissions before calling startService() method.
```kotlin
class MainActivity : AppCompatActivity() {
private var permissions: Array = arrayOf(
Manifest.permission.RECORD_AUDIO,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
companion object {
private const val REQUEST_PERMISSIONS = 200
}
override fun onCreate(savedInstanceState: Bundle?) {
...
requestPermissions(permissions, REQUEST_PERMISSIONS)
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
val flag = if (requestCode == REQUEST_PERMISSIONS) {
grantResults.all { it == PackageManager.PERMISSION_GRANTED }
} else {
false
}
if (!flag) {
Toast.makeText(applicationContext, "Permissions rejected.", Toast.LENGTH_SHORT).show()
finish()
}
}
}
```
#### Step 3. After the permissions granted, call startService() method.
```kotlin
val intent = Intent(applicationContext, AudioService::class.java)
startService(intent)
```
#### Step 4. call stopService() method if you don't use the service anymore.
If you call stopService() method during audio recording, a recorded audio file is automatically created.
```kotlin
val intent = Intent(applicationContext, AudioService::class.java)
stopService(intent)
```