Created
September 12, 2013 03:24
-
-
Save yaoxinghuo/6532756 to your computer and use it in GitHub Desktop.
Androd 判断某应用是否含有自启动和桌面小插件功能
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 检查某个包 是否有自启动或者桌面小插件 | |
* | |
* @param context | |
* @return 0 木有 1有自启动 2有小插件 3都有 | |
*/ | |
public static int checkStartupAndWidget(Context context, String packageName) { | |
PackageManager pm = context.getPackageManager(); | |
boolean haveStartup = false; | |
boolean haveWidget = false; | |
try { | |
PackageInfo pkgInfo = pm | |
.getPackageInfo(packageName, PackageManager.GET_RECEIVERS | |
| PackageManager.GET_META_DATA);// 通过包名,返回包信息 | |
haveStartup = pm.checkPermission( | |
"android.permission.RECEIVE_BOOT_COMPLETED", packageName) == PackageManager.PERMISSION_GRANTED; | |
ActivityInfo[] receivers = pkgInfo.receivers; | |
if (receivers != null) { | |
inner: for (ActivityInfo activityInfo : receivers) { | |
System.out.println("rece:" + activityInfo.name); | |
Bundle b = activityInfo.metaData; | |
if (b != null) { | |
if (b.containsKey("android.appwidget.provider")) { | |
haveWidget = true; | |
break inner; | |
} | |
} | |
} | |
} | |
} catch (NameNotFoundException e) { | |
return 0; | |
} | |
if (haveStartup && haveWidget) | |
return 3; | |
if (haveStartup) | |
return 1; | |
if (haveWidget) | |
return 2; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment