简体   繁体   中英

how to check if Google Assistant is available in a device by code?

Is Google Assistant available in all Android devices?

Is there any way to check it programmatically?

I need to know if the current device has it available in order to offer some options to the user. As far as I know, at least new Huawei Android devices will not come with any Google features, right? Neither the Assistant. So is there a way to check that? Maybe a function like this:

IsGoogleAssistantAvailable()

Use this method to check if app is installed-

private boolean appInstalledOrNot(String uri) {
    PackageManager pm = getPackageManager();
    try {
        pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
    }

    return false;
}

Check like this

For Google Assistant-

boolean isAppInstalled = appInstalledOrNot("com.google.android.apps.googleassistant");  

For Google Assistant Go use this package name - com.google.android.apps.assistant

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM