我的计算机上有一个本地运行的Spring REST api.我想在Android开发中使用这个api.
这是我的获取请求:
public static String sendGet(final String url) {
StringBuilder result = new StringBuilder();
HttpURLConnection urlConnection = null;
try {
String apiUrl = getAbsoluteUrl(url); // concatenate uri with base url eg: localhost:8080/ + uri
URL requestUrl = new URL(apiUrl);
urlConnection = (HttpURLConnection) requestUrl.openConnection();
urlConnection.connect(); // no connection is made
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
} catch (Exception e) {
e.printStackTrace();
} …Run Code Online (Sandbox Code Playgroud) 我要求用户接受对照片库和相机使用的访问权限.我希望能够处理用户不接受的情况,但我遇到了这样的问题.以下是检查用户权限时的代码:
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo) { granted in
if granted {
if(!self.captureSession.isRunning){
self.setupCustomCamera()
}
} else {
self.takePhotoButton.alpha = 0.5
self.takePhotoButton.isEnabled = false
self.showNeedAccessMessage()
}
}
Run Code Online (Sandbox Code Playgroud)
我的showNeedAccessMessage()如下:
func showNeedAccessMessage() {
let alert = UIAlertController(title: "Camera Settings", message: "Please adjust your device settings to grant access to camera use.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { (action: UIAlertAction) -> Void in
self.dismiss(animated: true, completion: nil)
}))
show(alert, sender: nil)
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是,当granted案件不符合时,我想表示警告.我的应用程序尝试打开"图像设置"页面而不是我的警报显示,该页面显示如下:

这种情况是否有默认处理?如果是这样,任何想法如何修复黑色'图像设置'屏幕?
先感谢您!