How to get package name of camera application

前端 未结 4 2061
陌清茗
陌清茗 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:44

    I guess it is impossible or possible with some precision. You can enumerate all system packages (applications that are provided with the device) and try to select the package that has CAMERA permission. But this approach can give you several applications, because several applications can use camera for their needs. But in general case I guess this is impossible.

    0 讨论(0)
  • 2021-01-06 16:47

    Did you try this?

        PackageManager packman = getPackageManager();
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        String pack = intent.resolveActivity(packman).getPackageName();
    
    0 讨论(0)
  • 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<ResolveInfo> 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..

    0 讨论(0)
  • 2021-01-06 16:53

    see http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-icon

    class PInfo {
        private String appname = "";
        private String pname = "";
        private String versionName = "";
        private int versionCode = 0;
        private Drawable icon;
        private void prettyPrint() {
            Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
        }
    }
    
    private ArrayList<PInfo> getPackages() {
        ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
        final int max = apps.size();
        for (int i=0; i<max; i++) {
            apps.get(i).prettyPrint();
        }
        return apps;
    }
    
    private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
        ArrayList<PInfo> res = new ArrayList<PInfo>();        
        List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
        for(int i=0;i<packs.size();i++) {
            PackageInfo p = packs.get(i);
            if ((!getSysPackages) && (p.versionName == null)) {
                continue ;
            }
            PInfo newInfo = new PInfo();
            newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
            newInfo.pname = p.packageName;
            newInfo.versionName = p.versionName;
            newInfo.versionCode = p.versionCode;
            newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
            res.add(newInfo);
        }
        return res; 
    }
    
    0 讨论(0)
提交回复
热议问题