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感謝您的回覆。我已將代碼添加到問題中。 –