Search code examples
searchvoice

Most efficient way to detect Google Voice Search installation on Android device


I wanted to ask,... What would be the most efficient way to detect the Google Voice Search (app id: com.google.android.voicesearch) installation on Android device? And is there any way of subsequently installing it without taking user to Play Market and back to application?


Solution

  • You can use the below method

    private boolean voiceSearchExists() {
        final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
        final List<ResolveInfo> pkgAppsList = getPackageManager().queryIntentActivities( mainIntent, 0);
        boolean packageExists = false;
        boolean activityExists = false;
        for(PackageInfo r:packs){
            String pkg = r.applicationInfo.packageName;
            if(pkg != null && pkg.equals("com.google.android.googlequicksearchbox")){
                packageExists = true;
                break;
            }
        }
        if(packageExists == false)
            return false;
    
        for(ResolveInfo r:pkgAppsList){ 
            ActivityInfo info = r.activityInfo;
            if(info!=null && info.name!=null && info.name.equals("com.google.android.googlequicksearchbox.VoiceSearchActivity")){
                activityExists = true;
                break;
            }
        }
        return activityExists;
    }