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
- My account is blocked so please check an...
My account is blocked so please unblock my account because all the apps are closed due to which it is causing a lot of problems
- Deep Linking & Password reset
I am using react native with expo. I want to implement deep link with the url recived via email. So when clicked the link it opens my app. I havent ever used de...
- custom domain with CloudFlare
Hi all, it seems that CloudFlare has blocked cross-domain CNAME link which made my app hostname which is in CloudFlare, unable to create a CNAME pointing to clo...