对于21岁以上的新API权限,我有点迷失了。我的分数是21,目标是23。
我在我的清单中有这个:
func textFieldDidBeginEditing(_ textField: UITextField) {
if textField == self.textField {
//self.textField.isHidden = false
self.pickerView.isHidden = false
textField.endEditing(true)
}
这是对的吗?即使他们没有相机,人们也可以下载我的应用程序吗?
答案 0 :(得分:0)
人们可以正常下载您的应用。但是,如果目标SDK是23,则必须实现运行时权限。这意味着您必须在运行时检查并请求相机权限。
默认情况下,不授予“摄像机”权限。如果您不检查它,您的应用程序将崩溃。
以下是在API 23上使用运行时权限的教程 Link
答案 1 :(得分:0)
你可以使用谷歌easypermission库它很容易使用
在您的活动中覆盖 onRequestPermissionsResult ,如下所示:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// Forward results to EasyPermissions
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}
}
然后实现Permission Callback
public class MainActivity extends AppCompatActivity
implements EasyPermissions.PermissionCallbacks {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// Forward results to EasyPermissions
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}
@Override
public void onPermissionsGranted(int requestCode, List<String> list) {
// Some permissions have been granted
// ...
}
@Override
public void onPermissionsDenied(int requestCode, List<String> list) {
// Some permissions have been denied
// ...
}
}
请求像这样的照相机:
@AfterPermissionGranted(RC_CAMERA_PERM)
public void cameraTask() {
if (EasyPermissions.hasPermissions(this, Manifest.permission.CAMERA)) {
// Have permission, do the thing!
Toast.makeText(this, "TODO: Camera things", Toast.LENGTH_LONG).show();
} else {
// Ask for one permission
EasyPermissions.requestPermissions(this, getString(R.string.rationale_camera),
RC_CAMERA_PERM, Manifest.permission.CAMERA);
}
}
更多代码示例检查easypermission android
的这个github存储库快乐编码