{"id":24501053,"url":"https://github.com/androidcrypto/cameraxinjavaupdate","last_synced_at":"2025-03-15T07:24:14.084Z","repository":{"id":223112813,"uuid":"477786577","full_name":"AndroidCrypto/CameraXinJavaUpdate","owner":"AndroidCrypto","description":null,"archived":false,"fork":false,"pushed_at":"2022-04-04T16:50:53.000Z","size":102,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T22:28:35.577Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AndroidCrypto.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-04-04T16:37:14.000Z","updated_at":"2022-04-04T16:37:29.000Z","dependencies_parsed_at":"2024-02-18T11:48:07.545Z","dependency_job_id":null,"html_url":"https://github.com/AndroidCrypto/CameraXinJavaUpdate","commit_stats":null,"previous_names":["androidcrypto/cameraxinjavaupdate"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndroidCrypto%2FCameraXinJavaUpdate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndroidCrypto%2FCameraXinJavaUpdate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndroidCrypto%2FCameraXinJavaUpdate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndroidCrypto%2FCameraXinJavaUpdate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndroidCrypto","download_url":"https://codeload.github.com/AndroidCrypto/CameraXinJavaUpdate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243697700,"owners_count":20332998,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-21T22:23:03.802Z","updated_at":"2025-03-15T07:24:14.049Z","avatar_url":"https://github.com/AndroidCrypto.png","language":"Java","funding_links":["https://www.buymeacoffee.com/codingreel"],"categories":[],"sub_categories":[],"readme":"# CameraX-In-Java\n\n## Update to grant permissions inside the app\n\nThe basic code is NOT MINE but written by Faisal-FS and is published here:\n\nSource: https://github.com/Faisal-FS/CameraX-In-Java\n\nVideo tutorial:\n\nYoutube: https://www.youtube.com/watch?v=IrwhjDtpIU0\n\nThis update asks the user to grant neccessary permissions inside the app - you do \nnot need to set the permissions in Settings/find app/etc.\n\nThese permissions are captured: access to the Camera, Record Audio and External Storage.\n\nTo append the changes to an existing app add the following code lines:\n\nin class definition:\n```plaintext\n// new for check and grant permissions within the app\nprivate boolean isReadPermissionGranted = false;\nprivate boolean isWritePermissionGranted = false;\nprivate boolean isCameraPermissionGranted = false;\nprivate boolean isRecordAudioPermissionGranted = false;\nActivityResultLauncher\u003cString[]\u003e myPermissionResultLauncher;\n```\n\nat the end of onCreate method:\n```plaintext\n        myPermissionResultLauncher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback\u003cMap\u003cString, Boolean\u003e\u003e() {\n            @Override\n            public void onActivityResult(Map\u003cString, Boolean\u003e result) {\n                if (result.get(Manifest.permission.READ_EXTERNAL_STORAGE) != null) {\n                    isReadPermissionGranted = result.get(Manifest.permission.READ_EXTERNAL_STORAGE);\n                }\n                if (result.get(Manifest.permission.WRITE_EXTERNAL_STORAGE) != null) {\n                    isWritePermissionGranted = result.get(Manifest.permission.WRITE_EXTERNAL_STORAGE);\n                }\n                if (result.get(Manifest.permission.CAMERA) != null) {\n                    isCameraPermissionGranted = result.get(Manifest.permission.CAMERA);\n                }\n                if (result.get(Manifest.permission.RECORD_AUDIO) != null) {\n                    isRecordAudioPermissionGranted = result.get(Manifest.permission.RECORD_AUDIO);\n                }\n            }\n        });\n\n        // check and request read and write permissions\n        // don't place this above\n        // mPermissionResultLauncher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback\u003cMap\u003cString, Boolean\u003e\u003e()\n        requestPermission();\n```\n\nbelow the onCreate method:\n```plaintext\n    private void requestPermission() {\n        boolean minSDK = Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.Q;\n        isReadPermissionGranted = ContextCompat.checkSelfPermission(\n                this,\n                Manifest.permission.READ_EXTERNAL_STORAGE\n        ) == PackageManager.PERMISSION_GRANTED;\n        isWritePermissionGranted = ContextCompat.checkSelfPermission(\n                this,\n                Manifest.permission.WRITE_EXTERNAL_STORAGE\n        ) == PackageManager.PERMISSION_GRANTED;\n        isWritePermissionGranted = isWritePermissionGranted || minSDK;\n        isCameraPermissionGranted = ContextCompat.checkSelfPermission(\n                this,\n                Manifest.permission.CAMERA\n        ) == PackageManager.PERMISSION_GRANTED;\n        isRecordAudioPermissionGranted = ContextCompat.checkSelfPermission(\n                this,\n                Manifest.permission.RECORD_AUDIO\n        ) == PackageManager.PERMISSION_GRANTED;\n        List\u003cString\u003e permissionRequest = new ArrayList\u003cString\u003e();\n        if (!isReadPermissionGranted) {\n            permissionRequest.add(Manifest.permission.READ_EXTERNAL_STORAGE);\n        }\n        if (!isWritePermissionGranted) {\n            permissionRequest.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);\n        }\n        if (!isCameraPermissionGranted) {\n            permissionRequest.add(Manifest.permission.CAMERA);\n        }\n        if (!isRecordAudioPermissionGranted) {\n            permissionRequest.add(Manifest.permission.RECORD_AUDIO);\n        }\n        if (!permissionRequest.isEmpty()) {\n            myPermissionResultLauncher.launch(permissionRequest.toArray(new String[0]));\n        }\n```\n\nI'm for shure this can get shortened but I leave it as it is for better readability.\n\nadditional note: DO NOT UPDATE androidx.camera:camera-view higher than cameraxviewVersion = \"1.0.0-alpha25\".\nThe newer versions doesn't contain \"PreviewView\" and you get a lot of hassle to get the code to run again :-)\n\n### Tutorial\nThis project is a reference code made for the video 'Camera X in Java | Image Capture, Video Capture, Image Analysis'.\n\nLink: https://youtu.be/IrwhjDtpIU0\n\n## Getting Started\n\nThese instructions will get you a copy of the project up and running on your local machine.\n\n### Prerequisites\n\nThe things you need before installing the software.\n\n* Android Studio\n\n## Installation\nClone this repository and import into **Android Studio**\n```bash\ngit clone git@github.com:Faisal-FS/CameraX-In-Java.git\n```\n\n## Configuration\n### Gradle Dependencies:\n```\ndependencies {\n    def cameraxVersion = \"1.1.0-alpha05\"\n    implementation \"androidx.camera:camera-core:${cameraxVersion}\"\n    implementation \"androidx.camera:camera-camera2:${cameraxVersion}\"\n    implementation \"androidx.camera:camera-lifecycle:${cameraxVersion}\"\n\n    // CameraX View class\n    implementation 'androidx.camera:camera-view:1.0.0-alpha25'\n}\n```  \n### Permissions:\nFirst enable permissions from the app info in device settings.\n\n```\n* Camera\n* Microphone\n* Read/Write External Storage\n```  \n\nDid I help you out? Consider buying me a coffee 😎\n\nhttps://www.buymeacoffee.com/codingreel\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandroidcrypto%2Fcameraxinjavaupdate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandroidcrypto%2Fcameraxinjavaupdate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandroidcrypto%2Fcameraxinjavaupdate/lists"}