Skip to content

Latest commit

 

History

History
261 lines (184 loc) · 9.64 KB

PREREQUISITE.md

File metadata and controls

261 lines (184 loc) · 9.64 KB

Table of Contents

Prerequisite

You need to do two actions.

  1. Add euphony to your project
  2. Edit your AndroidManifest.xml to permit euphony to record audio.

1. Add euphony to your project

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

1.1 Using Maven repository


  1. Show Project window with Android project view. You can select a project view mode in the dropdown list, then open your build.gradle file under Gradle Scripts.

maven_001_auto_x2_colored_toned

  1. Add the following line to the dependencies section:
dependencies {
	// other dependencies
	// ...
	implementation 'co.jbear.lib:euphony:0.7.1.6'
}

1.2 Import the aar/jar file directly


Environment

OS : Windows 10
Android Studio : Arctic Fox | 2020.3.1

  1. Download euphony.aar : MavenCentral euphony artifact follow the link and download aar file

aar_001

  1. Put euphony.aar file in libs folder, and just click Refactor

aar_002_auto_x2_colored_toned

aar_003_auto_x2_colored_toned

  1. 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!!

1.3 Import the Euphony module in your project

Environment

OS : Mac OS Big Sur
Android Gradle Plugin Version : 4.2.1 Gradle Version : 6.7.1 Language : Java

  1. Download an zip file at https://github.com/euphony-io/euphony and unzip it in your computer

module_001

  1. Click File > New > Import Module...

module_002

module_003

  1. Put what you downloaded before in source directory and click Finish

module_004

! The summary below covers some possible errors. Unfold it if you need.

Possible errors module_005

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 kotlin
module_006

If you want to know more about 'Gradle', https://www.baeldung.com/gradle-build-settings-properties will be helpful

module_007

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')

module_008
  1. Now, we'll gonna add a dependency. In File > Project Structure, click + button at Dependencies > app. Then click Module Dependency

module_009

module_010

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


2. Edit your AndroidManifest.xml

Add the following line to the AndroidManifest.xml:

<uses-permission android:name="android.permission.RECORD_AUDIO" />

Request permission to users

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.

https://user-images.githubusercontent.com/50264056/129441912-2058e3b3-391d-48f0-a5ff-38ee27e82f0a.png

https://user-images.githubusercontent.com/50264056/129441943-3fc854db-c432-42d4-a3ab-8e07d77e0daf.png

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.