俄语网站推广,工程公司名称大全,crm管理系统软件哪家好,广州网站建设熊掌号在compileSDK 33 时#xff0c;谷歌在安卓新增了 图片选择器 功能#xff0c;支持单选、多选、选图片、视频等操作#xff0c;并且不需要额外获取照片/音频权限。
具体实现如下#xff1a;
1#xff1a;请求 Log.d(TAG, Build.VERSION.SDK_INT Build.VERS…在compileSDK 33 时谷歌在安卓新增了 图片选择器 功能支持单选、多选、选图片、视频等操作并且不需要额外获取照片/音频权限。
具体实现如下
1请求 Log.d(TAG, Build.VERSION.SDK_INT Build.VERSION.SDK_INT);if (Build.VERSION.SDK_INT 33) {//图片选择器单选
// Intent intent new Intent(MediaStore.ACTION_PICK_IMAGES);
// 在complieSDK32已废弃
// startActivityForResult(intent, PHOTO_PICKER_REQUEST_CODE);//图片选择器多选final int maxNumPhotosAndVideos 3;Intent intent new Intent(MediaStore.ACTION_PICK_IMAGES);
// intent.setType(video/*);//仅选择视频intent.setType(image/*);//仅选择图片intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, maxNumPhotosAndVideos);launcher.launch(intent);} else {//我们需要自己开发}
2响应
2.1单选 Overrideprotected void onActivityResult(int requestCode, int resultCode, Nullable Intent data) {super.onActivityResult(requestCode, resultCode, data);if (resultCode RESULT_OK) {if (requestCode PHOTO_PICKER_REQUEST_CODE) {Uri currentUri null;if (data ! null) {currentUri data.getData();binding.image.setImageURI(currentUri);}Log.d(TAG, currentUri: currentUri);}}}
2.2多选 launcher registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),new ActivityResultCallbackActivityResult() {Overridepublic void onActivityResult(ActivityResult result) {if (result ! null) {if (result.getData() ! null result.getResultCode() RESULT_OK) {Intent intent result.getData();for (int i 0; i intent.getClipData().getItemCount(); i) {Uri uri intent.getClipData().getItemAt(i).getUri();Log.d(TAG, multiple current Uri: uri);// Do stuff with each photo/video URI.}}}}});