4

How to open default camera in your application?

I don't want to open chooser for it (its client's requirement). I am using this intent android.media.action.IMAGE_CAPTURE and calling activity for result.

Everything is fine but apps like Line Camera, Paper Camera are appearing in chooser with default camera app, i don't want to show chooser for.

Your attentions will be highly appreciated.

Nauman Zubair
  • 1,208
  • 15
  • 27

3 Answers3

2
    List<ApplicationInfo> list = packageManager.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(packageManager).toString());
            Log.d("TAG", "package name  : " + list.get(n).packageName);
            if(list.get(n).loadLabel(packageManager).toString().equalsIgnoreCase("Camera")) {
                defaultCameraPackage = list.get(n).packageName;
                break;
            }
        }
    }

I find following solution and its working perfectly.

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.setPackage(defaultCameraPackage); 
startActivityForResult(takePictureIntent, actionCode);

you can filter default camera by setting package in above intent. I've tested it by installing two application Line Camera and Paper Camera both apps were showing chooser but filtering by package above code open only default camera.

Nauman Zubair
  • 1,208
  • 15
  • 27
0

The only easy you can pick a specific activity is by using explicit intents. And for the built in camera app the package name could be different and device dependent

Pulkit Sethi
  • 1,325
  • 1
  • 14
  • 22
0

I believe you can find your answer(and code) in the link below:

How to launch android camera using intents

The author states there specifically that: "the code above should start the default Camera activity on your phone"

salsayk
  • 21
  • 3
  • This code doesn't filter 3rd party application, it will open chooser if application like **Line Camera** or **Paper Camera** are installed in your phone – Nauman Zubair Sep 27 '13 at 12:58