Back

No such class found Error.

  • 0
  • Android
HOT
4 Oct, 2023, 12:54

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");

TypeScript
            // 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
        }
    });
TL;DR
Make sure to add the `androidx.appcompat` library to the project. If you're using Appwrite, wrap your code in backticks for better formatting. The issue is with the `ActivityResultContracts`, which cannot be found. The solution is to use `registerForActivityResult` instead of `startActivityForResult`.
Drake
5 Oct, 2023, 01:18

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.

Drake
5 Oct, 2023, 01:19

Also, is this related to Appwrite at all?

darShan
5 Oct, 2023, 04:53

Make sure to add the androidx.appcompat library to the project.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more