private String getAppInstaller(Context context, String packageName) {
return context.getPackageManager().getInstallerPackageName(packageName);
}
在/system/app 或者 /system/priv-app目录下的应用。
public boolean isSystem(Context context, String packageName) {
try {
PackageManager packageManager = context.getPackageManager();
ApplicationInfo appInfo = packageManager.getApplicationInfo(packageName, 0);
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
return true;
}
if ((appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
return true;
}
} catch (PackageManager.NameNotFoundException e) {
return false;
}
return false;
}
包括状态栏和导航栏高度。
public int getFullHeight(){
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getRealMetrics(metrics);
int fullWindowHeight = metrics.heightPixels;
return fullWindowHeight;
}
public int getNavigationBarHeight() {
Context context = this;
int result = 0;
int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
public int getStatusBarHeight(Context context) {
int statusBarHeight = 0;
Resources resources = context.getResources();
int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = resources.getDimensionPixelSize(resourceId);
}
return statusBarHeight;
}
在网上看到一篇总结的非常全面的工具类。
android常用工具类