Adonis Hart 5:25 AM Hello I have issue with ActivityResultContracts. I am trying to take photo and save it to the backend database. Thus I have to invoke the camera intent in my activity code, but during this process, I got stuck. The method startActivityForResult has already been deprecated, thus I have to use the registerActivityForResult(). So I tried the below code, but the ActivityResultContracts cannot not be found anywhere. I would be grateful if anyone has similar experience with this issue. 🙂 ActivityResultLauncher<Intent> cameraLauncher = registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), result -> { if (result.getResultCode() == RESULT_OK) { Intent data = result.getData(); Bitmap photo = (Bitmap) data.getExtras().get("data");
// Save the photo to external storage
File photoFile = new File(Environment.getExternalStorageDirectory(), "photo.jpg");
try {
FileOutputStream fos = new FileOutputStream(photoFile);
photo.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
// Upload the photo file to the backend database using appropriate APIs or libraries
// Implement your backend integration logic here
}
});
FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.
Also, is this related to Appwrite at all?
Make sure to add the androidx.appcompat library to the project.
Recommended threads
- Otp is not coming
Otp is not coming plz check and fix the issue
- Display an in-app in the user mobile?
Would it be possible to send a message that would display an in-app in the user mobile?
- Project stuck in read-only mode on free ...
Hi Appwrite team! I’m a student using the free plan, and my project (ID: 68e48f780001232ad879) is currently stuck in read-only mode. I can’t create or update ...