You need to do two actions.
- Add euphony to your project
- Edit your AndroidManifest.xml to permit euphony to record audio.
There are 3 ways adding euphony to your project.
1. Using Maven repository
2. Import the aar/jar file directly
3. 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 your
build.gradle
file underGradle Scripts
.
- Add the following line to the
dependencies
section:
dependencies {
// other dependencies
// ...
implementation 'co.jbear.lib:euphony:0.7.1.6'
}
OS : Windows 10
Android Studio : Arctic Fox | 2020.3.1
- Download
euphony.aar
: MavenCentral euphony artifact follow the link and download aar file
- Put
euphony.aar
file inlibs
folder, and just clickRefactor
- Check your
build.gradle
in app module
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
implementation name: 'euphony-0.7.1.6', ext: 'aar'
}
then click sync
and you can use euphony library!!
OS : Mac OS Big Sur
Android Gradle Plugin Version : 4.2.1 Gradle Version : 6.7.1 Language : Java
- Download an 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
! The summary below covers some possible errors. Unfold it if you need.
Possible errors
If Could not get unknown property 'language' for build 'import_Euphony' of type org.gradle.invocation.DefaultGradle. error occur, please add a sentence below in setting.gradle(Project) and click 'Sync Now'
gradle.ext.language = "java"; // or kotlinIf you want to know more about 'Gradle', https://www.baeldung.com/gradle-build-settings-properties will be helpful
If Caused by: groovy.lang.MissingPropertyException: Cannot get property 'signing.keyId' on extra properties extension as it does not exist error occur, please delete the sentence below in euphony/gradle.build and click 'Sync Now'apply from: file('publish.gradle')
- 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')
...
}
Path could be different, if you change module name at step 3
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
So, 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 14, we must consider two types app 14<= sdk < 16 app and sdk >= 16 app.
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.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
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);
button = findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int permission = ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.RECORD_AUDIO);
if (permission == PackageManager.PERMISSION_DENIED) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{
Manifest.permission.RECORD_AUDIO}, 1000);
}
}
}
});
}
//after requestPermission
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(requestCode == 1000) {
boolean check_result = true;
for (int result : grantResults) {
if (result != PackageManager.PERMISSION_GRANTED) {
check_result = false;
break;
}
}
if(check_result == true) {
} else {
finish();
}
}
}
}
This is MainActivity
for adding permission.
int permission = ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.RECORD_AUDIO);
if (permission == PackageManager.PERMISSION_DENIED) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{
Manifest.permission.RECORD_AUDIO}, 1000);
}
}
We can know whether permission is denied or not. And we also consider both sdk version is higher than 16 which is mashmellow and call function requestPermission.