Created
September 4, 2023 07:17
-
-
Save asadfareed777/de5c1c9e9237014d548c1dc12bd4d2d9 to your computer and use it in GitHub Desktop.
Add these functions in your PickerUtilicty class. It will always open system default camera no matter what camera set as default.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void captureImageFromCamera() { | |
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
File path = AppFolders.getImageFilePath(); | |
if (!path.exists()) { | |
path.mkdirs(); | |
} | |
File file = new File(AppFolders.getRandomImageFilePath()); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | |
imageCaptureUri = FileProvider.getUriForFile(mContext, LWMCApplication.getInstance().getPackageName() + ".provider", getRandomFileName()); | |
} else { | |
imageCaptureUri = Uri.fromFile(file); | |
} | |
String defaultCamera = getPackageCamera(); | |
if (!defaultCamera.isEmpty()){ | |
intent.setPackage(defaultCamera); | |
} | |
intent.putExtra("return-data", true); | |
intent.putExtra(MediaStore.EXTRA_OUTPUT, | |
imageCaptureUri); | |
if (mFragmentContext != null) { | |
startChildActivityFragment(intent, PIC_FROM_CAMERA); | |
} else { | |
startChildActivity(intent, PIC_FROM_CAMERA); | |
} | |
} | |
private String getPackageCamera(){ | |
String defaultCameraPackage = ""; | |
List<ApplicationInfo> list = getPackageManager().getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES); | |
for (int n=0;n<list.size();n++) { | |
if((list.get(n).flags & ApplicationInfo.FLAG_SYSTEM)==1) | |
{ | |
Log.d("TAG", "Installed Applications : " + list.get(n).loadLabel(getPackageManager()).toString()); | |
Log.d("TAG", "package name : " + list.get(n).packageName); | |
if(list.get(n).loadLabel(getPackageManager()).toString().equalsIgnoreCase("Camera")) { | |
defaultCameraPackage = list.get(n).packageName; | |
break; | |
} | |
} | |
} | |
return defaultCameraPackage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment