I want the user to be able to quickly open the default camera app (or one they have set as default) in my app. However, I do not want to use android.media.action.IMAGE_CAPTURE, as this will only show the photo taking portion of the app. I just want to simply open the camera app without using this. I do know that this is possible, as several gallery apps that I have used (Most notibale: Focus) have been able to just simply open the camera app with no issue, and did not use IMAGE_CAPTURE.
Open Default Camera App Without Using action.Image_Capture
2.8k Views Asked by pancodemakes At
4
There are 4 best solutions below
0

If you want to just open default camera app, use the code below
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivity(
getPackageManager().getLaunchIntentForPackage(
intent.resolveActivity(getPackageManager()).getPackageName()));
0

String intentpackage;
List<ApplicationInfo> list = packageManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
for (int a=0;a<list.size();a++) {
if((list.get(n).flags & ApplicationInfo.FLAG_SYSTEM)==1)
{
Log.d("TAG", "Installed Applications : " + list.get(a).loadLabel(packageManager).toString());
Log.d("TAG", "package name : " + list.get(a).packageName);
if(list.get(a).loadLabel(packageManager).toString().equalsIgnoreCase("Camera")) {
intentpackage = list.get(a).packageName;
break;
}
}
}
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(defaultCameraPackage!=null){
cameraIntent.setPackage(intentpackage);
}
startActivityForResult(cameraIntent, 1);
0

I'm adding this comment as an update for Android 11+, because the accepted answer did not work for me before adhering to the package visibility changes.
For it to work, I've added this to the AndroidManifest.xml.
<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
and, based on the accepted answer, the code to launch the camera app is:
fun resolveAndLaunchCameraApp() {
try {
val imageCaptureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
val packageManager = requireContext().packageManager
val resolveInfo: ResolveInfo = packageManager.resolveActivity(imageCaptureIntent, 0) ?: throw Exception("Could not resolve activity!")
val applicationInfo: ApplicationInfo =
resolveInfo.activityInfo?.applicationInfo ?:
resolveInfo.serviceInfo?.applicationInfo ?:
resolveInfo.providerInfo?.applicationInfo ?: throw Exception("ApplicationInfo not found!")
val launchIntent = packageManager.getLaunchIntentForPackage(applicationInfo.packageName) ?: throw Exception("Launch intent not found!")
requireContext().startActivity(launchIntent)
}
catch (exc: Exception) {
// handle exception
}
}
This can be achieved by using
PackageManager#resolveActivity(Intent)
In Kotlin:
(Where
cameraIntent
is the Intent created using theandroid.media.action.IMAGE_CAPTURE
filter,context
is the current app context andpackageManager
is the context'sPackageManager
instance.)