Commit 16d01223 by Denglingling

完善【借货订单】拒绝录音的提示、增加安卓打开手机【设置】文件

parent 5fcb7d55
......@@ -13,6 +13,7 @@ import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.bonehouse_business_app.opensettings.*;
import java.util.Arrays;
import java.util.List;
......@@ -34,7 +35,8 @@ public class MainApplication extends Application implements ReactApplication {
new RNSoundPackage(),
new ReactNativeAudioPackage(),
new RNGestureHandlerPackage(),
new ImagePickerPackage()
new ImagePickerPackage(),
new OpenSettingsPackage() /* add */
);
}
......
package com.bonehouse_business_app.opensettings;
import android.app.Activity;
import android.content.Intent;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
public class OpenSettingsModule extends ReactContextBaseJavaModule {
@Override
public String getName() {
/**
* return the string name of the NativeModule which represents this class in JavaScript
* In JS access this module through React.NativeModules.OpenSettings
*/
return "OpenSettings";
}
@ReactMethod
public void openNetworkSettings(Callback cb) {
Activity currentActivity = getCurrentActivity();
if (currentActivity == null) {
cb.invoke(false);
return;
}
try {
currentActivity.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
cb.invoke(true);
} catch (Exception e) {
cb.invoke(e.getMessage());
}
}
/* constructor */
public OpenSettingsModule(ReactApplicationContext reactContext) {
super(reactContext);
}
}
\ No newline at end of file
package com.bonehouse_business_app.opensettings;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class OpenSettingsPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new OpenSettingsModule(reactContext));
return modules;
}
// @Override
// public List<<Class>? extends JavaScriptModule> createJSModules() {
// return Collections.emptyList();
// }
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
\ No newline at end of file
......@@ -7,7 +7,11 @@ import {
ScrollView,
TouchableOpacity,
Image,
TextInput
TextInput,
Alert,
Linking,
NativeModules,
Platform
} from 'react-native';
import {
home_background_color,
......@@ -267,7 +271,22 @@ class EquipConsuPage extends Component {
.then(isAuthor => {
console.log('是否授权: ' + isAuthor)
if(!isAuthor) {
return alert('请前往设置开启录音权限')
// return alert('APP需要使用录音,请打开录音权限允许APP使用')
return Alert.alert('提示信息', 'APP需要使用录音,请打开录音权限允许APP使用', [{
text: '设置',
onPress: () => {
if(Platform.OS == 'ios') {
Linking.openURL('app-settings:')
.catch(err => console.log('error', err))
} else if(Platform.OS == 'android') {
NativeModules.OpenSettings.openNetworkSettings(data => {
console.log('call back data', data)
}).catch(err => console.log('android---', err))
}
}
}, {
text: '取消',
}])
}
this.setState({hasPermission: isAuthor})
this.prepareRecordingPath(this.state.audioPath);
......@@ -309,18 +328,96 @@ class EquipConsuPage extends Component {
// 开始录音
_record = async () => {
show('录音开始')
console.log('-----this.state.hasPermission---', this.state.hasPermission)
// 【有问题】
// let {hasPermission} = this.state
// if(!hasPermission) {
// AudioRecorder.requestAuthorization()
// .then(async (isAuthor) => {
// console.log('是否授权: ' + isAuthor)
// if(!isAuthor) {
// // return Alert.alert('提示信息','APP需要使用录音,请打开录音权限允许APP使用')
// return Alert.alert('提示信息', 'APP需要使用录音,请打开录音权限允许APP使用', [{
// text: '设置',
// onPress: () => {
// if(Platform.OS == 'ios') {
// Linking.openURL('app-settings:')
// .catch(err => console.log('error', err))
// } else if(Platform.OS == 'android') {
// NativeModules.OpenSettings.openNetworkSettings(data => {
// console.log('call back data', data)
// }).catch(err => console.log('android---', err))
// }
// }
// }, {
// text: '取消',
// }])
// }
// console.log('this.state.hasPermission---!!----', this.state.hasPermission)
// this.setState({hasPermission: isAuthor})
// this.prepareRecordingPath(this.state.audioPath);
// // 录音进展
// AudioRecorder.onProgress = (data) => {
// this.setState({
// currentTime: Math.ceil(data.currentTime)
// });
// };
// // 完成录音
// AudioRecorder.onFinished = (data) => {
// // data 录音数据
// console.log(this.state.currentTime)
// };
// show('录音开始!!')
// if(this.state.stop) {
// // 初始化录音
// this.prepareRecordingPath(this.state.audioPath)
// }
// try {
// // await AudioRecorder.startRecording()
// } catch (err) {
// console.log('start record-!!-error->',err)
// }
// })
// } else {
// console.log('---否则---')
// show('录音开始')
// if(this.state.stop) {
// // 初始化录音
// this.prepareRecordingPath(this.state.audioPath)
// }
// try {
// await AudioRecorder.startRecording()
// } catch (err) {
// console.log('start record--error->',err)
// }
// }
if(!this.state.hasPermission) {
return alert('没有授权')
}
if(this.state.recording) {
return alert('正在录音中...')
return Alert.alert('提示信息', 'APP需要使用录音,请打开录音权限允许APP使用', [{
text: '设置',
onPress: () => {
if(Platform.OS == 'ios') {
Linking.openURL('app-settings:')
.catch(err => console.log('error', err))
} else if(Platform.OS == 'android') {
NativeModules.OpenSettings.openNetworkSettings(data => {
console.log('call back data', data)
}).catch(err => console.log('android---', err))
}
}
}, {
text: '取消',
}])
// return
}
show('录音开始')
if(this.state.stop) {
// 初始化录音
this.prepareRecordingPath(this.state.audioPath)
}
this.setState({ recording: true })
try {
await AudioRecorder.startRecording()
} catch (err) {
......@@ -330,12 +427,17 @@ class EquipConsuPage extends Component {
// 停止录音
_stop = async () => {
console.log('----stop---', this.state.hasPermission)
if(!this.state.hasPermission) {
return
// return alert('没有授权')
}
show('录音结束')
try {
await AudioRecorder.stopRecording();
this.setState({ stop: true, recording: false });
this.setState({ stop: true });
} catch (error) {
console.error(error);
console.log('stop record--error->', error);
}
}
......@@ -346,15 +448,14 @@ class EquipConsuPage extends Component {
self.whoosh = new Sound(this.state.audioPath, '', (err) => {
if(err) {
show('加载音频失败')
return console.warn(err)
return console.log('加载音频失败-->',err)
}
self.whoosh.play(success => {
if(success) {
console.warn('success - 播放成功')
show('播放完毕')
}else {
console.warn('fail - 播放失败')
show('播放失败')
console.log('fail - 播放失败')
}
})
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment