【2025年1月2日】关于腾讯云小程序平台更名为腾讯云超级应用服务的公告
控制台更新动态
Android SDK 更新动态
iOS SDK 更新动态
Flutter 更新动态
IDE 更新动态
基础库更新动态
wx.chooseImage、wx.chooseVideo、wx.chooseMedia时触发。/*** 从相册选择媒体文件* @param context* @param options* @param listener* @return*/public boolean chooseMediaFromAlbum(Activity context, ChooseMediaOptions options, ChooseMediaProxy.IChooseMediaListener listener)/*** 从相机拍摄媒体文件* @param context* @param options* @param listener* @return*/public boolean chooseMediaFromCamera(Activity context, ChooseMediaOptions options, ChooseMediaProxy.IChooseMediaListener listener)
public static final int REQUEST_CHOOSE_MEDIA = 110;public static final int REQUEST_CHOOSE_MEDIA_CAMERA = 111;@Overridepublic void chooseMediaFromAlbum(Activity context, ChooseMediaOptions options, IChooseMediaListener listener) {try {TmfMiniSDK.addActivityResultListener(new IActivityResultListener() {@Overridepublic boolean doOnActivityResult(int requestCode, int resultCode, Intent data) {if (requestCode == REQUEST_CHOOSE_MEDIA && resultCode == Activity.RESULT_OK) {ArrayList<Uri> picturePath = new ArrayList<>();if (data == null) {Log.e(TAG, "empty intent ,failed getting from chooseImage");listener.onResult(false, null);return false;}if (null != data.getClipData()) {Log.d(TAG, "use clipdata as intent uri ");ClipData clipData = data.getClipData();for (int i = 0; i < clipData.getItemCount(); i++) {picturePath.add(clipData.getItemAt(i).getUri());}Log.d(TAG, "send to mini with path " + picturePath.size());} else if (null != data.getData()) {Log.d(TAG, "select picture path is " + data.getData());picturePath.add(data.getData());}listener.onResult(true, picturePath);} else {listener.onResult(false, null);}MiniSDK.removeActivityResultListener(this);return true;}});Intent chooserIntent = new Intent(Intent.ACTION_GET_CONTENT);if (options.maxCount > 1) {chooserIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);}switch (options.mediaType) {case ChooseMediaOptions.MEDIA_TYPE_IMAGE:chooserIntent.setType("image/*");break;case ChooseMediaOptions.MEDIA_TYPE_VIDEO:chooserIntent.setType("video/*");break;case ChooseMediaOptions.MEDIA_TYPE_MIX:chooserIntent.setType("*/*");chooserIntent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"image/*", "video/*"});default:chooserIntent.setType("image/*");break;}context.startActivityForResult(chooserIntent, REQUEST_CHOOSE_MEDIA);} catch (Exception e) {listener.onResult(false, null);}}@Overridepublic void chooseMediaFromCamera(Activity context, ChooseMediaOptions options, IChooseMediaListener listener) {Intent takePhotoIntent;if (options.mediaType == ChooseMediaOptions.MEDIA_TYPE_VIDEO) {takePhotoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);int duration = options.duration;if (duration < 1 || duration > 60000) {duration = 60000;}takePhotoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, duration);if (options.camera == ChooseMediaOptions.CAMERA_TYPE_FRONT) {takePhotoIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);}} else {takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);}if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {takePhotoIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);}if (takePhotoIntent.resolveActivity(context.getPackageManager()) == null) {Log.e(TAG, "resolveActivity failed ,has no camera app");listener.onResult(false, null);return;}if (options.cameraOutput == null) {Log.e(TAG, "createImageFile failed ");listener.onResult(false, null);return;}Uri imageUri = options.cameraOutput;takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);context.startActivityForResult(takePhotoIntent, REQUEST_CHOOSE_MEDIA_CAMERA);TmfMiniSDK.addActivityResultListener(new IActivityResultListener() {@Overridepublic boolean doOnActivityResult(int requestCode, int resultCode, Intent data) {if (requestCode != REQUEST_CHOOSE_MEDIA_CAMERA) {return false;}if (resultCode != Activity.RESULT_OK) {listener.onResult(false, null);} else {ArrayList<Uri> picturePath = new ArrayList<>();picturePath.add(imageUri);listener.onResult(true, picturePath);}MiniSDK.removeActivityResultListener(this);return true;}});}
文档反馈