1
我正在使用麦克风开发Xamarin.Forms应用程序。我的应用在华为P9-Phone上使用Android 7.1(牛轧糖)。我的Android清单包括:Android权限对话框在Xamarin.Forms中没有显示
仍然允许对话框没有显示,如果我尝试使用麦克风。我可以在手机设置中手动设置权限(应用程序如果我这样做)。
访问麦克风的代码是:
this.recorder = new MediaRecorder();
this.recorder.SetAudioSource(AudioSource.Mic);
this.recorder.SetOutputFormat(OutputFormat.AmrWb);
this.recorder.SetAudioEncoder(AudioEncoder.AmrWb);
this.recorder.SetAudioSamplingRate(16000);
var directoryName = Configuration.RecordDirectory;
if (!Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
}
var fileName = Configuration.RecordName + Configuration.RecordExtension;
string path = Path.Combine(Configuration.RecordDirectory, fileName);
this.recorder.SetOutputFile(path);
this.recorder.Prepare();
this.recorder.Start();
我缺少什么?
我可以在运行时强制应用程序显示对话框吗?
解决
阅读this blog article,开发人员必须手动执行的权限请求由于Android MARSHMELLOW。
请表明正在尝试访问麦克风 – Jason
由于Android 6.0的代码您必须以编程方式请求权限:https://developer.android.com/training/permissions/requesting.html – Gusman
@jason感谢您的回复。我已将代码添加到问题中。 –