在 Android 應用中,需要直接啟動系統預設相機進行拍照,要求:
使用隱式 Intent 配合 MediaStore.ACTION_IMAGE_CAPTURE,並通過 setPackage 鎖定系統相機包名,即可實現直達系統相機。
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// 關鍵:指定系統相機包名,避免彈出選擇器
intent.setPackage("com.android.camera"); // 部分設備可能為 com.google.android.GoogleCamera
// 若不指定保存路徑,系統會將縮略圖返回於 onActivityResult 的 data 中
startActivityForResult(intent, REQUEST_CODE_CAMERA);
com.android.camera、com.google.android.GoogleCamera)。MediaStore.EXTRA_OUTPUT 並提供 Uri(需處理 FileProvider 適配 Android 7.0+)。AndroidManifest.xml 聲明相機權限:<uses-permission android:name="android.permission.CAMERA" />。詳細實現可參考:Android 打開系統相機不彈出選擇器的完整代碼