You need to do two actions.
- Import
euphony
library to your project - Add
android.permission.RECORD_AUDIO
inAndroidManifest.xml
There are 3 ways adding euphony to your project.
- Using Maven repository
- Import the aar/jar file directly
- Import the Euphony module in your project
- Show Project window with Android project view.
You can select a project view mode in the dropdown list, then open yourbuild.gradle
file underGradle Scripts
.
- Add the following line to the
dependencies
section:
dependencies {
// other dependencies
// ...
implementation 'co.euphony.lib:euphony:0.8.1.2'
}
- Download
euphony.aar
: MavenCentral euphony artifact follow the link and download aar file. - Put
euphony.aar
file inlibs
folder.
- Check your
build.gradle
in app module
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
implementation name: 'euphony-0.8.1.2', ext: 'aar'
}
then click sync
and you can use euphony library.
- Download the zip file at https://github.com/euphony-io/euphony and unzip it in your computer
- Click
File
>New
>Import Module...
- Put what you downloaded before in source directory and click
Finish
- Now, we'll gonna add a dependency. In
File
>Project Structure
, click+
button atDependencies
>app
. Then clickModule Dependency
After that, you can see a sentence is added in build.gradle(Module:app)
dependencies{
...
implementation project(path: ':euphony')
...
}
Add the following line to the AndroidManifest.xml
:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Plus, you should consider that the permission model is different depending on the user's android version. Its details is below.
Show details
if you wanna use this library in the right way, you should check your permission manually in app configuration. That's because after Android 6.0 Marshmallow, Android introduced a new permissions model that lets apps request permissions from the user at runtime, rather than prior to installation.You can read a below docs to check details.https://developer.android.com/training/permissions/usage-notes?hl=en
So when you develop the android app, you should consider when app requests permission to users, and you should typing codes that requests permssions to users.
Over the all, as this library's minimun sdk is 21.
Let's check out how can it possible. The sample code below is an example of adding permission through the UI. Please refer to it.
Let's look up the code.
package com.example.euphonytest;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import android.Manifest;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] permissions = {
Manifest.permission.RECORD_AUDIO
// add other permissions
};
// after requestPermissions
ActivityResultLauncher<String[]> multiplePermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), grantResults -> {
for(Boolean result : grantResults.values()) {
if (!result) {
finish();
}
}
});
button = findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
multiplePermissionLauncher.launch(permissions);
}
}
});
}
}
This is MainActivity
for adding permission.
String[] permissions = {
Manifest.permission.RECORD_AUDIO
// add other permissions
};
// after requestPermissions
ActivityResultLauncher<String[]> multiplePermissionLauncher = registerForActivityResult(new
ActivityResultContracts.RequestMultiplePermissions(), grantResults -> {
for(Boolean result : grantResults.values()) {
if (!result) {
finish();
}
}
});
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
multiplePermissionLauncher.launch(permissions);
}
We can know whether permissions are denied or not. And we also consider both sdk version is higher than 16 which is marshmallow and call function RequestMultiplePermissions.