安卓判断快捷方式是否存在

2015-07-09 0 282
安卓判断快捷方式是否存在

public static boolean isAddShortCut(Context context) {

        boolean isInstallShortcut = false;

        final ContentResolver cr = context.getContentResolver();

        String AUTHORITY = getAuthorityFromPermission(context, "com.android.launcher.permission.READ_SETTINGS");

        final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true");

        Cursor c = cr.query(CONTENT_URI, new String[] {"title"}, "title=?", new String[] {context.getString(R.string.app_name)}, null);

        if (c != null && c.getCount() > 0) {

            isInstallShortcut = true;

        }

        if (c != null) {

            c.close();

        }

        return isInstallShortcut;

    }

    public static String getAuthorityFromPermission(Context context, String permission) {

        if (TextUtils.isEmpty(permission)) {

            return null;

        }

        List<PackageInfo> packInfos = context.getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS);

        if (packInfos == null) {

            return null;

        }

        for (PackageInfo info : packInfos) {

            ProviderInfo[] providers = info.providers;

            if (providers != null) {

                for (ProviderInfo provider : providers) {

                    if (permission.equals(provider.readPermission) || permission.equals(provider.writePermission)) {

                        return provider.authority;

                    }

                }

            }

        }

        return null;

    }

遇见资源网 java 安卓判断快捷方式是否存在 http://www.ox520.com/9493.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务