How to get package name of camera application

前端 未结 4 2093
陌清茗
陌清茗 2021-01-06 16:33

Thanks for previous replies,

Is it possible to get Package name of camera application which is installed on the device? If the OS is customized the default package n

4条回答
  •  情书的邮戳
    2021-01-06 16:49

    I am not sure, but I think you can get package name of application using specified intent..

    Look at this code for getting available application information which handle the specific intent,

    /**
     * Indicates whether the specified action can be used as an intent. This
     * method queries the package manager for installed packages that can
     * respond to an intent with the specified action. If no suitable package is
     * found, this method returns false.
     *
     * @param context The application's environment.
     * @param action The Intent action to check for availability.
     *
     * @return True if an Intent with the specified action can be sent and
     *         responded to, false otherwise.
     */
    public static boolean isIntentAvailable(Context context, String action) {
        final PackageManager packageManager = context.getPackageManager();
        final Intent intent = new Intent(action);
        List list =
                packageManager.queryIntentActivities(intent,
                        PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    }
    

    Now using Camera intent you can get the application information which handles the IMAGE_CAPTURE intent and using that information you can easily get package name.

    Update:

    In your case the specific intent is

    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    

    EDIT:

    List listCam = packageManager.queryIntentActivities(intent, 0);
    for (ResolveInfo res : listCam) {
        Log.e("Camera Application Package Name and Activity Name",res.activityInfo.packageName + " " + res.activityInfo.name));
    }
    

    Try this and let me know what happen..

提交回复
热议问题