Example usage for android.content.pm LauncherApps hasShortcutHostPermission

List of usage examples for android.content.pm LauncherApps hasShortcutHostPermission

Introduction

In this page you can find the example usage for android.content.pm LauncherApps hasShortcutHostPermission.

Prototype

public boolean hasShortcutHostPermission() 

Source Link

Document

Returns whether the caller can access the shortcut information.

Usage

From source file:com.farmerbb.taskbar.activity.ContextMenuActivity.java

@TargetApi(Build.VERSION_CODES.N_MR1)
private int getLauncherShortcuts() {
    LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);
    if (launcherApps.hasShortcutHostPermission()) {
        UserManager userManager = (UserManager) getSystemService(USER_SERVICE);

        LauncherApps.ShortcutQuery query = new LauncherApps.ShortcutQuery();
        query.setActivity(ComponentName.unflattenFromString(componentName));
        query.setQueryFlags(//  www.j  a v a  2s .com
                LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC | LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST
                        | LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED);

        shortcuts = launcherApps.getShortcuts(query, userManager.getUserForSerialNumber(userId));
        if (shortcuts != null)
            return shortcuts.size();
    }

    return 0;
}