- android 权限检查
private static void checkPermission(Context context, String name) {
if ( PackageManager.PERMISSION_GRANTED != context.checkCallingOrSelfPermission(name)) {
Log.e(LogUtils.TAG, "Permission: " + name + " DENIED");
}
}
调用方式
//检查短信发送权限
checkPermission(context, android.Manifest.permission.SEND_SMS);
/**
* 调用系统相册
*/
private void requestGallery() {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
intent.putExtra("crop", "true");
intent.putExtra("noFaceDetection", true);
intent.putExtra("scale", true);
intent.putExtra("scaleUpIfNeeded", true);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 120);
intent.putExtra("outputY", 120);
intent.putExtra("return-data", true);
startActivityForResult(intent, SELECT_PICTURE);
}
/**
* 调用系统拍照
*/
private void requestCapture() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("noFaceDetection", true);
intent.putExtra("scale", true);
intent.putExtra("scaleUpIfNeeded", true);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 120);
intent.putExtra("outputY", 120);
intent.putExtra("return-data", true);
File file = new File(getCameraPath());
if (!file.getParentFile().exists())
file.getParentFile().mkdirs();
Uri picUri = Uri.fromFile(file);</span>
intent.putExtra(MediaStore.EXTRA_OUTPUT, picUri);
startActivityForResult(intent, CROP_FROM_CAMERA);
}