startRecording fails on android X ?
See original GitHub issue2.0.1
flutter doctor
flutter doctor -v [✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Linux, locale en_AU.UTF-8) • Flutter version 1.12.13+hotfix.5 at /home/bsutton/apps/flutter • Framework revision 27321ebbad (6 weeks ago), 2019-12-10 18:15:01 -0800 • Engine revision 2994f7e1e6 • Dart version 2.7.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) • Android SDK at /home/bsutton/Android/Sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-29, build-tools 29.0.2 • Java binary at: /home/bsutton/apps/android-studio/jre/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405) • All Android licenses accepted.
[✓] Android Studio (version 3.5) • Android Studio at /home/bsutton/apps/android-studio • Flutter plugin version 42.1.1 • Dart plugin version 191.8593 • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] Connected device (1 available) • Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• No issues found!
Platforms you faced the error (IOS or Android or both?)
Android
Expected behavior
When I call startRecording the system should start recording.
Actual behavior
The call to startRecording fails silently.
Tested environment (Emulator? Real Device?)
Emulator
Steps to reproduce the behavior
Call startRecording.
So I’ve dug into the code and found the source of the error:
The method:
checkRecordPermission in FlutterSoundPlugin.java (line 42) calls:
reg.activity()
which is returning a null.
Line 44 then passes the null activity to :
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.RECORD_AUDIO,}, 0);
The call to requestPermissions then throws an NPE.
Looking at the documentation I suspect this is occurring as I’m running a later version of Flutter/Dart.
The documentation on Registrar.activty()
has instructions for migrating a plugin from Flutters v1 embedding to Flutters v2 embedding. It would appear that flutter_sound is still using the v1 method which is why I suspect this bug is showing up now.
So it looks like the code needs to be migrated as per:
For instructions on migrating a plugin from Flutter’s v1 Android embedding to v2, visit http://flutter.dev/go/android-plugin-migration
Can I also suggest that you put a try/catch block around each top level method so that you can log and report an appropriate error to the calling application rather than just failing silently.
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (3 by maintainers)
Top GitHub Comments
So I pulled latest version 2.0.3 and method
String _file = await _flutterSound.startRecorder(uri: _soundFilename);
seems to be doing nothing.Yes, this could be a good planing. I am not a flutter expert, but my first tries to be compatible with V1 and V2 is encouraging. Flutter documentation is good, and there is no much code to be compatible.
I will take you inform later (this evening or tomorrow) of my advancement.