Android ACTION_IMAGE_CAPTURE Intent

后端 未结 14 2220
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 02:04

We are trying to use the native camera app to let the user take a new picture. It works just fine if we leave out the EXTRA_OUTPUT extra and returns the small B

14条回答
  •  情书的邮戳
    2020-11-22 02:44

    You can use this code

    private Intent getCameraIntent() {
    
        PackageManager packageManager = mContext.getPackageManager();
        List list = packageManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
        Intent main = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        List launchables = packageManager.queryIntentActivities(main, 0);
        if (launchables.size() == 1)
            return packageManager.getLaunchIntentForPackage(launchables.get(0).activityInfo.packageName);
        else
            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);
                    String defaultCameraPackage = list.get(n).packageName;
    
    
                    if (launchables.size() > 1)
                        for (int i = 0; i < launchables.size(); i++) {
                            if (defaultCameraPackage.equals(launchables.get(i).activityInfo.packageName)) {
                                return packageManager.getLaunchIntentForPackage(defaultCameraPackage);
                            }
                        }
                }
            }
        return null;
    }
    

提交回复
热议问题