清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
判断用户是否开启某个服务
public static boolean serviceIsStart(Context cont, String className) { ActivityManager mActivityManager = (ActivityManager) cont .getSystemService(cont.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> mServiceList = mActivityManager .getRunningServices(30); for (int i = 0; i < mServiceList.size(); i++) { if (className.equals(mServiceList.get(i).service.getClassName())) { return true; } } return false; }
判断是否安装了某个软件
public static boolean isInstall(Context cont, String packName) { PackageManager packageManager = cont.getPackageManager(); List<PackageInfo> list = packageManager .getInstalledPackages(PackageManager.GET_PERMISSIONS); for (PackageInfo packageInfo : list) { if (packageInfo.packageName.equals(packName)) { return true; } } return false; }
获取手机串号唯一标示
public static String getMIEI(Context context) { String MIEI; TelephonyManager telephonemanage = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); try { MIEI = telephonemanage.getDeviceId(); return MIEI; } catch (Exception e) { Log.i("error", e.getMessage()); return null; } }
获取版本
public static int getVersionCode(Context context) throws Exception { PackageManager packageManager = context.getPackageManager(); PackageInfo packInfo = packageManager.getPackageInfo( context.getPackageName(), 0); int version = packInfo.versionCode; return version; }
获取手机内所有应用
public static List<PackageInfo> getAllApps(Context context) { List<PackageInfo> apps = new ArrayList<PackageInfo>(); PackageManager pManager = context.getPackageManager(); // 获取手机内所有应用 List<PackageInfo> paklist = pManager.getInstalledPackages(0); for (int i = 0; i < paklist.size(); i++) { PackageInfo pak = (PackageInfo) paklist.get(i); // 判断是否为非系统预装的应用程序 if ((pak.applicationInfo.flags & pak.applicationInfo.FLAG_SYSTEM) <= 0) { // customs applications apps.add(pak); } } return apps; }
通过包名获取Apk名字
public static String getApkName(Context context, String packeName) { PackageManager pManager = context.getPackageManager(); List<PackageInfo> appList = getAllApps(context); for (int i = 0; i < appList.size(); i++) { if (appList.get(i).packageName.equals(packeName)) { return pManager.getApplicationLabel( appList.get(i).applicationInfo).toString(); } } return null; }
判断手机GPS是否开启
<span style="white-space:pre"> </span>public static boolean gpsIsOpen(Context context) { LocationManager alm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) { return true; } return false; }
判断是手机品牌
public static boolean isHTC() { String MODEL = android.os.Build.MODEL; if (MODEL.contains("HTC")) { return true; } else return false; }
设置手机系统亮度
public static void setSystemLight(Activity activity, int light) { ContentResolver cr = activity.getContentResolver(); Settings.System.putInt(cr, "screen_brightness", light); Window window = activity.getWindow(); LayoutParams attributes = window.getAttributes(); float flevel = light; attributes.screenBrightness = flevel / 255; float x = attributes.screenBrightness; activity.getWindow().setAttributes(attributes); }