Skip to content

Fix runtime permission; Update gradle, support library #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "cafe.adriel.androidaudiorecorder.example"
minSdkVersion 15
targetSdkVersion 24
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
Expand All @@ -19,8 +19,11 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:appcompat-v7:25.3.0'
compile project(':lib')
compile ('com.karumi:dexter:2.3.1'){
exclude group: 'com.android.support'
}
// compile 'com.github.adrielcafe:AndroidAudioRecorder:0.1.0'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
import android.view.View;
import android.widget.Toast;

import com.karumi.dexter.Dexter;
import com.karumi.dexter.MultiplePermissionsReport;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.multi.MultiplePermissionsListener;

import java.util.List;

import cafe.adriel.androidaudiorecorder.AndroidAudioRecorder;
import cafe.adriel.androidaudiorecorder.model.AudioChannel;
import cafe.adriel.androidaudiorecorder.model.AudioSampleRate;
Expand All @@ -19,19 +27,33 @@ public class MainActivity extends AppCompatActivity {
private static final int REQUEST_RECORD_AUDIO = 0;
private static final String AUDIO_FILE_PATH =
Environment.getExternalStorageDirectory().getPath() + "/recorded_audio.wav";
private boolean hasPermission = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Dexter.initialize(this.getApplicationContext());

if (getSupportActionBar() != null) {
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(ContextCompat.getColor(this, R.color.colorPrimaryDark)));
}

Util.requestPermission(this, Manifest.permission.RECORD_AUDIO);
Util.requestPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
Dexter.checkPermissions(new MultiplePermissionsListener() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport report) {
if (report.areAllPermissionsGranted()){
hasPermission = true;
}
}

@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
token.continuePermissionRequest();
}
}, Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}

@Override
Expand All @@ -47,6 +69,10 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}

public void recordAudio(View v) {
if (! hasPermission){
Toast.makeText(this, "no permission", Toast.LENGTH_SHORT).show();
return;
}
AndroidAudioRecorder.with(this)
// Required
.setFilePath(AUDIO_FILE_PATH)
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.android.tools.build:gradle:2.3.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
8 changes: 4 additions & 4 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
minSdkVersion 15
targetSdkVersion 24
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
Expand All @@ -19,7 +19,7 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.kailashdabhi:om-recorder:1.1.0'
compile 'com.cleveroad:audiovisualization:1.0.0'
}