1 回答
TA贡献1797条经验 获得超6个赞
操作系统不支持发送到 的 。但是,支持库具有执行此操作的机制,该机制将调用注册到 中的特殊表。这里的诀窍是,你必须使用 自己的启动活动结果(),而不是 的一个。onActivityResult()FragmentAppCompatActivityFragmentActivity
因此,您的类代码应如下所示: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()
添加回答
举报