Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
zhangzhonghua
/
BoneHouse_Business_APP
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
16d01223
authored
Jun 04, 2020
by
Denglingling
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完善【借货订单】拒绝录音的提示、增加安卓打开手机【设置】文件
parent
5fcb7d55
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
193 additions
and
14 deletions
android/app/src/main/java/com/bonehouse_business_app/MainApplication.java
android/app/src/main/java/com/bonehouse_business_app/opensettings/OpenSettingsModule.java
android/app/src/main/java/com/bonehouse_business_app/opensettings/OpenSettingsPackage.java
app/containers/quickOrder/QuickOrderPage.js
android/app/src/main/java/com/bonehouse_business_app/MainApplication.java
View file @
16d01223
...
...
@@ -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 */
);
}
...
...
android/app/src/main/java/com/bonehouse_business_app/opensettings/OpenSettingsModule.java
0 → 100644
View file @
16d01223
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
android/app/src/main/java/com/bonehouse_business_app/opensettings/OpenSettingsPackage.java
0 → 100644
View file @
16d01223
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
app/containers/quickOrder/QuickOrderPage.js
View file @
16d01223
...
...
@@ -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 - 播放失败'
)
}
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment