1

我想问一下,... 在 Android 设备上检测Google 语音搜索(应用程序 ID:com.google.android.voicesearch)安装的最有效方法是什么?是否有任何方法可以在不将用户带到 Play Market 并返回应用程序的情况下随后安装它?

4

1 回答 1

2

您可以使用以下方法

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;
}
于 2013-02-08T20:53:13.240 回答