# java.lang.IllegalArgumentException: 无法将值转换为 Intent，类 android.content.Intent 不是有效类型

- **ID:** `android/activityresult-api-contract-mismatch`
- **领域:** android
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 87%

## 根因

ActivityResultContract 期望的输入/输出类型与 registerForActivityResult 中提供的不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| AndroidX Activity 1.7.2 | active | — | — |
| Android 14 (API 34) | active | — | — |
| Kotlin 1.9.0 | active | — | — |

## 解决方案

1. ```
   Ensure the contract matches the input type. For Intent, use ActivityResultContracts.StartActivityForResult() and pass Intent explicitly: registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> ... }
   ```
2. ```
   If using custom contract, override createIntent correctly. Example: class CustomContract : ActivityResultContract<Uri, Boolean>() { override fun createIntent(context: Context, input: Uri) = Intent(Intent.ACTION_VIEW, input) }
   ```

## 无效尝试

- **Use ActivityResultContracts.StartActivityForResult() without any type casting** — Still throws same error if Input class is not Intent; contract requires explicit type conversion. (80% 失败率)
- **Remove the contract entirely and use deprecated startActivityForResult** — Deprecated and won't compile on targetSdk 34+; also breaks modern lifecycle handling. (90% 失败率)
