tencent cloud

Tencent Cloud Super App as a Service

Release Notes and Announcements
Announcement: Tencent Cloud Mini Program Platform Renamed to Tencent Cloud Super App as a Service on January 2, 2025
Console Updates
Android SDK Updates
iOS SDK Updates
Flutter SDK Updates
IDE Updates
Base Library Updates
Product Introduction
Overview
Strengths
Use Cases
Purchase Guide
Billing Overview
Pay-As-You-Go Billing
Renewal Guide
Service Suspension Instructions
Getting Started
Plan Management
Overview
Console Account Management
Storage Configuration
Acceleration Configuration
Branding Configurations
Platform Features
Console Login
Users and Permission System
Mini Program Management
Mini Game Management
Superapp Management
Commercialization
Platform Management
User Management
Team Management
Operations Management
Security Center
Code Integration Guide
Getting Demo and SDK
Android
iOS
Flutter
Superapp Server
GUID Generation Rules
Mini Program Development Guide
Mini Program Introduction and Development Environment
Mini Program Code Composition
Guide
Framework
Components
API
Server Backend
JS SDK
Base Library
IDE Operation Instructions
Mini Game Development Guide
Guide
API
Server Backend
Practice Tutorial
Mini Program Login Practical Tutorial
Mini Program Subscription Message Practical Tutorial
Payment Practical Tutorial
Ad Integration Practical Tutorial
Mini Game Subscription Message Practical Tutorial
API Documentation
History
Introduction
API Category
Making API Requests
Operation Management APIs
User Management APIs
Team Management APIs
Sensitive API-Related APIs
Role Management APIs
Platform Management APIs
Other Console APIs
Mini Program or Mini Game APIs
Management-Sensitive APIs
Global Domain Management APIs
Superapp APIs
Data Types
Agreements
Service Level Agreement
Data Processing and Security Agreement
SDK Privacy Policy Module
SDK Data Processing and Security Agreement Module

Customizing Image Selection

PDF
Focus Mode
Font Size
Last updated: 2025-07-04 17:33:28
The mini program SDK provides a default image selection feature, which uses the Android system's built-in media picker when the mini program calls the multimedia selection (wx.chooseImage, wx.chooseVideo, wx.chooseMedia).
Custom image selection can be achieved by overriding the chooseMediaFromAlbum and chooseMediaFromCamera methods in the BaseMiniAppProxyImpl class.
API description:
Parameter context: The Activity instance of the current mini program page.
Parameter options: Media selection options. ChooseMediaOptions
Parameter listener: Image selection callback API. ChooseMediaProxy.IChooseMediaListener
Return value boolean: A return value of false indicates that the default image selection implementation is used, while a return value of true indicates that the custom image selection implementation is used.
/**
* Selects media files from the album
* @param context
* @param options
* @param listener
* @return
*/
public boolean chooseMediaFromAlbum(Activity context, ChooseMediaOptions options, ChooseMediaProxy.IChooseMediaListener listener)
/**
* Captures media files from the camera
* @param context
* @param options
* @param listener
* @return
*/
public boolean chooseMediaFromCamera(Activity context, ChooseMediaOptions options, ChooseMediaProxy.IChooseMediaListener listener)
Example:
public static final int REQUEST_CHOOSE_MEDIA = 110;
public static final int REQUEST_CHOOSE_MEDIA_CAMERA = 111;

@Override
public void chooseMediaFromAlbum(Activity context, ChooseMediaOptions options, IChooseMediaListener listener) {
try {
TmfMiniSDK.addActivityResultListener(new IActivityResultListener() {
@Override
public 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);
}
}

@Override
public 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() {
@Override
public 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;
}
});
}





Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback