Tencent/QMUI_Android · error · RuntimeException

no QMUIMediaPhotoProviderFactory is provided.

Error message

no QMUIMediaPhotoProviderFactory is provided.

What it means

QMUIPhotoPickerViewModel's init block reads the QMUI_PHOTO_PROVIDER_FACTORY key from the SavedStateHandle. If absent, it throws RuntimeException("no QMUIMediaPhotoProviderFactory is provided.") because the picker cannot instantiate its photo provider without knowing the factory class name. It then reflectively loads and instantiates that class.

Source

Thrown at photo/src/main/java/com/qmuiteam/photo/vm/QMUIPhotoPickerViewModel.kt:57

    var prevScene: QMUIPhotoPickerScene? = null
        private set

    private val _photoPickerDataFlow = MutableStateFlow(QMUIPhotoPickerData(QMUIPhotoPickerLoadState.permissionChecking, null))
    val photoPickerDataFlow = _photoPickerDataFlow.asStateFlow()

    private val _pickedMap = mutableMapOf<Long, QMUIMediaPhotoVO>()
    private val _pickedListFlow = MutableStateFlow<List<Long>>(emptyList())
    val pickedListFlow = _pickedListFlow.asStateFlow()

    private val _pickedCountFlow = MutableStateFlow(0)
    val pickedCountFlow = _pickedCountFlow.asStateFlow()

    private val _isOriginOpenFlow = MutableStateFlow(false)
    val isOriginOpenFlow = _isOriginOpenFlow.asStateFlow()

    init {
        val photoProviderFactoryClsName =
            state.get<String>(QMUI_PHOTO_PROVIDER_FACTORY) ?: throw RuntimeException("no QMUIMediaPhotoProviderFactory is provided.")
        photoProviderFactory = Class.forName(photoProviderFactoryClsName).newInstance() as QMUIMediaPhotoProviderFactory
    }

    fun updateScene(scene: QMUIPhotoPickerScene) {
        prevScene = _photoPickerSceneFlow.value
        _photoPickerSceneFlow.value = scene
    }

    fun permissionDenied() {
        _photoPickerDataFlow.value = QMUIPhotoPickerData(QMUIPhotoPickerLoadState.permissionDenied, null)
    }

    fun permissionGranted() {
        _photoPickerDataFlow.value = QMUIPhotoPickerData(QMUIPhotoPickerLoadState.dataLoading, null)
        viewModelScope.launch {
            try {
                val data = withContext(Dispatchers.IO) {
                    dataProvider.provide(application, supportedMimeTypes).map { bucket ->

View on GitHub (pinned to 026e7d4866)

Solutions

  1. Put the factory class name extra into the launch Intent: intent.putExtra(QMUI_PHOTO_PROVIDER_FACTORY, YourFactory::class.java.name).
  2. Use the library's picker builder/launcher helper which sets the extra for you.
  3. Ensure the factory class is instantiable (public, no-arg constructor) and not stripped by ProGuard (add keep rule).

Example fix

// before
startActivity(Intent(context, QMUIPhotoPickerActivity::class.java)) // throws
// after
startActivity(Intent(context, QMUIPhotoPickerActivity::class.java).putExtra(QMUI_PHOTO_PROVIDER_FACTORY, MyPhotoProviderFactory::class.java.name))
Defensive patterns

Strategy: validation

Validate before calling

val intent = Intent(context, QMUIPhotoPickerActivity::class.java)
require(intent.hasExtra(QMUI_PHOTO_PROVIDER_FACTORY)) { "QMUI_PHOTO_PROVIDER_FACTORY extra required" }

Try / catch

try { launcher.launch(intent) } catch (e: RuntimeException) { Log.e(TAG, "picker misconfigured", e) }

Prevention

When it happens

Trigger: Launching QMUIPhotoPickerActivity without putting a String under QMUI_PHOTO_PROVIDER_FACTORY into the launch Intent extras; the SavedStateHandle lookup returns null.

Common situations: Starting the picker activity directly without the required extra; key renamed between library versions; building the Intent manually instead of via the provided launcher helper; proguard/reflection failing later (Class.forName) after missing key check passes.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06). Data as JSON: /api/errors/13b9d28d5891fb06. Report an issue: GitHub.