public void CheckPermission(View view){ if(SdkVersion()) { int hasPermission = this.checkSelfPermission(Manifest.permission.CAMERA); if (hasPermission != PackageManager.PERMISSION_GRANTED) { this.requestPermissions(new String[]{Manifest.permission.CAMERA}, 100); } } } public boolean SdkVersion(){ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; }
注:permission替换成自己需要的权限!
弹出的Dialog是系统自带的样式!
朋友发给我的,自己还没有使用过!(*^__^*) 嘻嘻……先记录下来!