Android开发工具类public static String getDataTime(String format) {
SimpleDateFormat df=new SimpleDateFormat(format);return df.format(new Date());
*返回当前系统时间(格式以HH:mm形式)public static String getDataTime() {return getDataT ime(HH:mm
*获取手机I MEI码public static String getPhoneIMEI(Context cxt) {
TelephonyManager tm = (TelephonyManag er)cxt.getSystemServic e(Context.TELEP HONY_SERVICE);return tm.getDevic eI d();
*获取手机系统SDK版本
*@return如API 17则返回17public static int getSDKVersion() {return android.os.Build.VERS ION.SDK_INT;
*获取系统版本
*@r eturn形如2.3.3public static String getSystemVersion() {return android.os.Build.VERSION.RELEAS E;
*调用系统发送短信public static void sendSMS(Context cxt,String smsBody) {
Uri smsToUri=Uri.parse( smsto:
Intent intent=new Intent(Intent.ACTION_SENDTO, sms ToUri);intent.putExtra( s ms_body, s ms Body);c xt.s tartAc tivity(intent);
*判断网络是否连接public static boolean checkNet(Context context) {
ConnectivityManager cm = (ConnectivityManager)c ontext.getSystemS ervic e(Context.CONNECTIVITY_SERVI CE);
Netw orkInfo info=c m.getActiveNetw orkInfo();return info!=null;//网络是否连接
*判断是否为wifi联网public static boolean isWiFi(Context cxt) {
ConnectivityManager cm = (ConnectivityManager)c xt.getSystemS ervic e(Context.CONNECTIVIT Y_SERVIC E);
//wifi的状态 ConnectivityManager.TYP E_WIFI
//3G的状态 ConnectivityMan ager.TYPE_MO BILE
State state=cm.getNetworkInfo(ConnectivityManager.TYP E_WIFI).getState();return State.CONNECTED==state;
*隐藏系统键盘br
*b警告/b必须是确定键盘显示时才能调用public static void hideKeyBoard(Activity aty) {
((I nputMetho dManag er)aty.getSystemS ervic e(Context.INPUT_MET HOD_SERVIC E)).hideS oftInputFromWindow(aty.getCurrentF oc us().getWindow Token(), I nputMethodManager.HI DE_NOT_ALWAYS);
*判断当前应用程序是否后台运行
public static boolean isBackground(Context context) {
ActivityManager activityManager = (ActivityManager)c ontext.getSystemServic e(Context.ACTIVITY_SERVICE);
List ActivityManager.RunningAppProcessInfo appProcesses =ac tivityM anager.getRunn ing AppProc es s es();for(ActivityManager.RunningAppProcessInfo appProcess :appProcesses) {if(appProc ess.proc es sName.equals(c ontext.getPackageName())) {if (appProcess.importance ==Activ ityManager.RunningAppProc es sInfo.IMPORTANCE_BACKGRO UND) {
//后台运行return true;
} els e {
//前台运行r eturn fals e;r eturn fals e;
*判断手机是否处理睡眠public static boolean isSleeping(Context context) {
KeyguardManag er kgMgr = (KeyguardManag er)c ontext.getSystemS ervic e(Context.KEYGUARD_S ERVICE);boolean is S le ep ing=kgMgr.inKeyguardRestric tedInputMode();return is S leep ing;
*安装apk
*@param context
*@param file
public static void installApk(Context context,File file) {
Intent intent=new Intent();intent.s etAc tion(android.intent.ac tion.VIEWintent.addCategory(android.intent.c ategory.DEFAULTintent.s etType(applic at ion/vnd.android.pac kage-archiveintent.s etData(Uri.fromFile(file));intent.s etDataAndType(Uri.fromFile(file),applic ation/vnd.android.package-archiveintent.s etFlags(Intent.FLAG_ACTIVITY_NEW_TAS K);c ontext.startAc tivity(intent);
*获取当前应用程序的版本号public static String getApp Version(C ontext c ontext) {
String version=0try{vers ion = c ontext.getPac kageManager().getPac kageInfo(c ontext.getPac kageName(),
0).versionName;
} c atch(PackageManager.NameNotFoundExc eption e) {throw new KJException(SystemTool.class.getName()+the application not foundreturn vers ion;
*回到home后台运行public static void goHome(Context context) {
Intent mHomeIntent=new Intent(Intent.ACTION_MAIN);mHomeIntent.addCategory(Intent.CATEGO RY_HO ME);mHomeIntent.addFlags(Intent.FLAG_ACTIVIT Y_NEW_TAS K |
Intent.FLAG_ACTI VITY_RESET_TAS K_IF_NEED ED);c ontext.startAc tivity(m HomeIntent);
*获取应用签名
*@param context
*@param pkgNamepublic static String getSign(Context c ontext,String pkgName) {try{
PackageInfo pis = context.getPackageManager().getPackageInfo(pkgName,P ac kageManager.GET_S I GN ATURES);return hexdiges t(pis.s ignatures[0].toByte Array());
} c atch(NameNotFoundExc eption e) {throw new KJException(SystemTool.class.getName()+the+pkgName+ ‘s application notfo un d
*将签名字符串转换成需要的32位签名private static String hexdigest(byte[]paramArrayOfByte) {final char[]hexDigits={48,49,50,51,52,53,54,55,56,57,97,98,99, 100, 101, 102};try{
MessageDigest localMessageDigest=MessageDigest.getInstance(MD5loc alMes sageD igest.update(paramArrayOfByte);byte[]arrayOfByte=loc alMes s ageDig est.digest();char[]arrayOfChar=new char[32];for(int i=0, j=0;; i++, j++) {if(i=16) {return new String(arrayOfChar); }
int k=arrayOfByte[i];arrayOfChar[j]=hexDigits[(0xF k 4)];arrayOfChar[++j]=hexDigits[(k 0xF)];
} catch(Exc eption e) {}r eturn
*获取设备的可用内存大小
*@param cxt
*应用上下文对象c ontext
*@r eturn当前内存大小public static int getDevic eUsab leMemory(Context cxt) {
ActivityManager am = (ActivityManager)cxt.getSystemServic e(Context.ACTIVIT Y_SERVICE);
MemoryInfo mi=new MemoryInfo();am.getMemoryInfo(mi);
//返回当前系统的可用内存r eturn(int) (mi.availMem/ (1024* 1024));
*清理后台进程与服务
*@param cxt
*应用上下文对象c ontext
*@r eturn被清理的数量public static int gc(Context cxt) {long i=getDevic eUsab leMemory(cxt);int c ount=0;//清理掉的进程数
ActivityManager am = (ActivityManager)cxt.getSystemServic e(Context.ACTIVIT Y_SERVICE);
//获取正在运行的s ervic e列表
List RunningS erv ic eInfo s ervic eList=am.getRunningS ervic es(100);if(s ervic eList !=null)for (RunningS ervic eInfo s ervic e : s ervic eList) {if(s ervic e.pid==android.os.Proc ess.myPid())c ontinue;try{android.os.Process.killProcess(service.pid);c ount++;
} catch(Exc eption e) {e.getStackTrace();c ontinue;
//获取正在运行的进程列表
List RunningAppProcessInfo processList=am.getRunningAppProcesses();if(proc essList !=null)for (RunningAppProc es sInfo proc ess :proc essList) {
//一般数值大于RunningAppProc es sInfo.IMPORTANCE_SERVICE的进程都长时间没用或者空进程了
//一般数值大于RunningAppProcessInfo.IMPORTANCE_VISI BLE的进程都是非可见进程也就是在后台运行着if(process.importance RunningAppProcessInfo.IMPORTANCE_VISI BLE) {
//pkgLis t得到该进程下运行的包名
String[]pkgList=proc es s.pkgList;for(String pkgName :pkgList) {
try{am.killBac kgroundProc es s es(pkgName);c ount++;
} catch(Exc eption e) { //防止意外发生e.getStackTrace();c ontinue;
//清理了+(getDevic eUs ab leM emory(c xt) - i)+M内存return c ount;
}
搬瓦工在国内非常流行的主机商,以提供低价的vps著称.不过近几年价格逐渐攀升.不过稳定性和速度一向不错.依然深受国内vps爱好者喜爱.新上线的套餐经常卖到断货.支持支付宝,paypal很方便购买和使用.官网网站:https://www.bandwagonhost.com[不能直接访问,已墙]https://www.bwh88.net[有些地区不能直接访问]https://www.bwh81.net...
触摸云国内IDC/ISP资质齐全商家,与香港公司联合运营, 已超8年运营 。本次为大家带来的是双12特惠活动,美国高防|美国大宽带买就可申请配置升档一级[CPU内存宽带流量选一]升档方式:CPU内存宽带流量任选其一,工单申请免费升级一档珠海触摸云科技有限公司官方网站:https://cmzi.com/可新购免费升档配置套餐:地区CPU内存带宽数据盘价格购买地址美国高防 1核 1G10M20G 26...
Digital-vm是一家成立于2019年的国外主机商,商家提供VPS和独立服务器租用业务,其中VPS基于KVM架构,提供1-10Gbps带宽,数据中心可选包括美国洛杉矶、日本、新加坡、挪威、西班牙、丹麦、荷兰、英国等8个地区机房;除了VPS主机外,商家还提供日本、新加坡独立服务器,同样可选1-10Gbps带宽,最低每月仅80美元起。下面列出两款独立服务器配置信息。配置一 $80/月CPU:E3-...