1 回答

TA貢獻1797條經(jīng)驗 獲得超6個贊
操作系統(tǒng)不支持發(fā)送到 的 。但是,支持庫具有執(zhí)行此操作的機制,該機制將調(diào)用注冊到 中的特殊表。這里的訣竅是,你必須使用 自己的啟動活動結(jié)果(),而不是 的一個。onActivityResult()FragmentAppCompatActivityFragmentActivity
因此,您的類代碼應(yīng)如下所示:Camera
public class Camera{
public static void dispatchTakePictureIntent(Activity activity, Fragment fragment, File file) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) {
// Create the File where the photo should go
file = null;
try {
file = Camera.createImageFile(activity);
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (file != null) {
Uri photoURI = FileProvider.getUriForFile(activity,
"com.itcom202.weroom.fileprovider",
file );
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
fragment.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
}
}
請注意,最后一行使用 的FragmentstartActivityForResult()
添加回答
舉報