热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

android获取当前服务状态,Android获取和判断当前手机状态和信息

判断用户是否开启某个服务publicstaticbooleanserviceIsStart(Contextcont,StringclassName){ActivityManager

判断用户是否开启某个服务

public static boolean serviceIsStart(Context cont, String className) {

ActivityManager mActivityManager = (ActivityManager) cont

.getSystemService(cont.ACTIVITY_SERVICE);

List mServiceList = mActivityManager

.getRunningServices(30);

for (int i = 0; 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 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 getAllApps(Context context) {

List apps = new ArrayList();

PackageManager pManager = context.getPackageManager();

// 获取手机内所有应用

List paklist = pManager.getInstalledPackages(0);

for (int i = 0; i

PackageInfo pak = (PackageInfo) paklist.get(i);

// 判断是否为非系统预装的应用程序

if ((pak.applicationInfo.flags & pak.applicationInfo.FLAG_SYSTEM) <&#61; 0) {

// customs applications

apps.add(pak);

}

}

return apps;

}

通过包名获取Apk名字

public static String getApkName(Context context, String packeName) {

PackageManager pManager &#61; context.getPackageManager();

List appList &#61; getAllApps(context);

for (int i &#61; 0; i

if (appList.get(i).packageName.equals(packeName)) {

return pManager.getApplicationLabel(

appList.get(i).applicationInfo).toString();

}

}

return null;

}

判断手机GPS是否开启

public static boolean gpsIsOpen(Context context) {

LocationManager alm &#61; (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {

return true;

}

return false;

}

判断是手机品牌

public static boolean isHTC() {

String MODEL &#61; android.os.Build.MODEL;

if (MODEL.contains("HTC")) {

return true;

} else

return false;

}

设置手机系统亮度

public static void setSystemLight(Activity activity, int light) {

ContentResolver cr &#61; activity.getContentResolver();

Settings.System.putInt(cr, "screen_brightness", light);

Window window &#61; activity.getWindow();

LayoutParams attributes &#61; window.getAttributes();

float flevel &#61; light;

attributes.screenBrightness &#61; flevel / 255;

float x &#61; attributes.screenBrightness;

activity.getWindow().setAttributes(attributes);

}



推荐阅读
author-avatar
w果乐园地盘BSp
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有