How to open default camera without showing chooser

2020-04-12 02:50发布

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.

3条回答
劳资没心,怎么记你
2楼-- · 2020-04-12 03:25

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

查看更多
再贱就再见
3楼-- · 2020-04-12 03:27

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"

查看更多
可以哭但决不认输i
4楼-- · 2020-04-12 03:42
    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.

查看更多
登录 后发表回答