一般情况况下判断为以下代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/**
* 判断桌面是否已经创建了快捷图标
*
* @param context
* @param packageName
* @return
*/
public static boolean getIsOnDesktopByPkgName(Context context, String packageName) {
final ContentResolver cr = context.getContentResolver();
String authority =
"com.android.launcher.settings"
;
int sdk = android.os.Build.VERSION.SDK_INT;
if
(sdk >= 8 && sdk < 19) {
authority =
"com.android.launcher2.settings"
;
}
else
if
(sdk >= 19) {
authority =
"com.android.launcher3.settings"
;
}
Cursor c =
null
;
try
{
c = cr.query(CONTENT_URI,
new
String[] {
"title"
,
"intent"
},
""
,
new
String[] {},
null
);
if
(c !=
null
) {
final int intentIndex = c.getColumnIndexOrThrow(
"intent"
);
while
(c.moveToNext()) {
String intentDescription = c.getString(intentIndex);
Intent intent =
null
;
try
{
if
(!StringUtils.isEmpty(intentDescription)) {
intent = Intent.parseUri(intentDescription, 0);
}
}
catch
(URISyntaxException e) {
continue
;
}
if
(intent !=
null
&& intent.getComponent() !=
null
) {
String pkgName = intent.getComponent().getPackageName();
if
(packageName.equals(pkgName)) {
return
true
;
}
}
}
}
} finally {
if
(c !=
null
&& !c.isClosed()) {
c.close();
}
}
return
false
;
}
return
false
;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
public static boolean hasShortcut(Activity activity, String shortcutName) {
String url =
""
;
url =
"content://"
+ getAuthorityFromPermission(activity,
"com.android.launcher.permission.READ_SETTINGS"
)
+
"/favorites?notify=true"
;
ContentResolver resolver = activity.getContentResolver();
Cursor cursor = resolver.query(Uri.parse(url),
new
String[] {
"title"
,
"iconResource"
},
"title=?"
,
new
String[] { shortcutName },
null
);
if
(cursor !=
null
&& cursor.moveToFirst()) {
cursor.close();
return
true
;
}
return
false
;
}
|
| 上面的getAuthorityFromPermission(Activity activity,String shortcutname)代码如下: private static String getAuthorityFromPermission(Context context, String permission) {
if
(permission ==
null
)
return
null
;
List<PackageInfo> packs = context.getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS);
if
(packs !=
null
) {
for
(PackageInfo pack : packs) {
ProviderInfo[] providers = pack.providers;
if
(providers !=
null
) {
for
(ProviderInfo provider : providers) {
if
(permission.equals(provider.readPermission))
return
provider.authority;
if
(permission.equals(provider.writePermission))
return
provider.authority;
}
}
}
}
return
null
;
}
|