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;
}
IT狗为用户提供 在线ping、在线tcping、在线路由追踪、域名被墙检测、域名被污染检测 等实用工具。【工具地址】https://www.itdog.cn/【工具特色】1、目前同类网站中,在线ping 仅支持1次或少量次数的测试,无法客观的展现目标服务器一段时间的网络状况,IT狗Ping工具可持续的进行一段时间的ping测试,并生成更为直观的网络质量柱状图,让用户更容易掌握服务器在各地区、各线...
国外商家提供Windows系统的并不常见,CheapWindowsVPS 此次提供的 2 款 VPS 促销套餐,提供 5 折永久优惠码,优惠后月付 4.5 美元起,价格还是挺诱人的,VPS 不限流量,接入 1Gbps 带宽,8 个机房皆可选,其中洛杉矶机房还提供亚洲优化网络供选择,操作系统有 Windows 10 专业版、2012 R2、2016、Linux等。Cheap Windows VPS是...
提速啦的来历提速啦是 网站 本着“良心 便宜 稳定”的初衷 为小白用户避免被坑 由赣州王成璟网络科技有限公司旗下赣州提速啦网络科技有限公司运营 投资1000万人民币 在美国Cera 香港CTG 香港Cera 国内 杭州 宿迁 浙江 赣州 南昌 大连 辽宁 扬州 等地区建立数据中心 正规持有IDC ISP CDN 云牌照 公司。公司购买产品支持3天内退款 超过3天步退款政策。提速啦的市场定位提速啦主...