Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit 7579faf

Browse files
committed
fix: android
1 parent dd5f2e4 commit 7579faf

File tree

12 files changed

+50
-29
lines changed

12 files changed

+50
-29
lines changed

android/.project

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<projectDescription>
3-
<name>android_</name>
3+
<name>android</name>
44
<comment>Project android_ created by Buildship.</comment>
55
<projects>
66
</projects>
77
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
813
<buildCommand>
914
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
1015
<arguments>
1116
</arguments>
1217
</buildCommand>
1318
</buildSpec>
1419
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
1521
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
1622
</natures>
1723
<filteredResources>
1824
<filter>
19-
<id>1647995199383</id>
25+
<id>0</id>
2026
<name></name>
2127
<type>30</type>
2228
<matcher>

android/build.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ buildscript {
44

55
repositories {
66
google()
7-
jcenter()
7+
mavenCentral()
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:4.1.1'
11+
classpath 'com.android.tools.build:gradle:4.2.2'
1212
// noinspection DifferentKotlinGradleVersion
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414
}
@@ -27,9 +27,8 @@ def getExtOrIntegerDefault(name) {
2727

2828
android {
2929
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
30-
buildToolsVersion getExtOrDefault('buildToolsVersion')
3130
defaultConfig {
32-
minSdkVersion 16
31+
minSdkVersion 30
3332
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
3433
versionCode 1
3534
versionName "1.0"
@@ -52,7 +51,6 @@ android {
5251

5352
repositories {
5453
mavenCentral()
55-
jcenter()
5654
google()
5755

5856
def found = false

android/gradle.properties

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Transcribe_kotlinVersion=1.3.50
2-
Transcribe_compileSdkVersion=28
3-
Transcribe_buildToolsVersion=28.0.3
4-
Transcribe_targetSdkVersion=28
1+
Transcribe_kotlinVersion=1.4.10
2+
Transcribe_compileSdkVersion=30
3+
Transcribe_buildToolsVersion=30
4+
Transcribe_targetSdkVersion=30
5+
android.useAndroidX=true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.reactnativetranscribe">
3+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
34

45
</manifest>

android/src/main/java/com/reactnativetranscribe/TranscribeModule.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import com.facebook.react.modules.core.PermissionListener;
2121

2222
import androidx.annotation.NonNull;
23+
import androidx.core.app.ActivityCompat;
24+
import androidx.core.content.ContextCompat;
25+
2326
import javax.annotation.Nullable;
2427

2528
public class TranscribeModule extends ReactContextBaseJavaModule {
@@ -32,6 +35,8 @@ public class TranscribeModule extends ReactContextBaseJavaModule {
3235
private AudioRecord audioRecord;
3336
private boolean isRecording;
3437

38+
private static final int PERMISSION_REQUEST_CODE = 1;
39+
3540
int audioSource = MediaRecorder.AudioSource.MIC;
3641
int sampleRateInHz = 8000;
3742
int channelConfig = AudioFormat.CHANNEL_IN_MONO;
@@ -52,11 +57,21 @@ public String getName() {
5257
private void init(){
5358
Log.d(TAG,"init");
5459

55-
isRecording = false;
56-
audioRecord = new AudioRecord(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSize * 10);
60+
if (ContextCompat.checkSelfPermission(this.getCurrentActivity(),Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_DENIED) {
61+
Log.d("permission", "permission denied to RECORD_AUDIO - requesting it");
62+
String[] permissions = {Manifest.permission.RECORD_AUDIO};
63+
64+
ActivityCompat.requestPermissions(this.getCurrentActivity(), permissions, PERMISSION_REQUEST_CODE);
65+
66+
} else {
67+
// RECORD_AUDIO has been granted
5768

58-
if (audioRecord.getState() != AudioRecord.STATE_INITIALIZED) {
59-
Log.d(TAG, "Unable to initialize AudioRecord");
69+
isRecording = false;
70+
audioRecord = new AudioRecord(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSize * 10);
71+
72+
if (audioRecord.getState() != AudioRecord.STATE_INITIALIZED) {
73+
Log.d(TAG, "Unable to initialize AudioRecord");
74+
}
6075
}
6176
}
6277

example/android/.project

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<projectDescription>
3-
<name>android</name>
3+
<name>TranscribeExample</name>
44
<comment>Project android created by Buildship.</comment>
55
<projects>
66
</projects>
@@ -16,7 +16,7 @@
1616
</natures>
1717
<filteredResources>
1818
<filter>
19-
<id>1647995199379</id>
19+
<id>0</id>
2020
<name></name>
2121
<type>30</type>
2222
<matcher>

example/android/app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ import com.android.build.OutputFile
7676
*/
7777

7878
project.ext.react = [
79-
enableHermes: false, // clean and rebuild if changing
79+
enableHermes: false, // clean and rebuild if changing
80+
entryFile: 'index.tsx'
8081
]
8182

8283
apply from: "../../node_modules/react-native/react.gradle"

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<uses-permission android:name="android.permission.RECORD_AUDIO" />
55

66
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme" android:usesCleartextTraffic="true">
7-
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize">
7+
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="true">
88
<intent-filter>
99
<action android:name="android.intent.action.MAIN" />
1010
<category android:name="android.intent.category.LAUNCHER" />

example/android/build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
buildscript {
44
ext {
5-
buildToolsVersion = "28.0.3"
6-
minSdkVersion = 16
7-
compileSdkVersion = 28
8-
targetSdkVersion = 28
5+
minSdkVersion = 30
6+
compileSdkVersion = 31
7+
targetSdkVersion = 31
98
}
109
repositories {
1110
google()
1211
jcenter()
1312
}
1413
dependencies {
15-
classpath('com.android.tools.build:gradle:4.1.1')
14+
classpath('com.android.tools.build:gradle:4.2.2')
1615

1716
// NOTE: Do not place your application dependencies here; they belong
1817
// in the individual module build.gradle files

0 commit comments

Comments
 (0)