public class DeviceInfo {
private static application APP = NULL;
private static String Sd_card = Environment.getexternalstoragedirectory () +file.separator+ "Wlcache";
public static Application Getapp () {
return APP;
}
Get phone model
public static String GetInfo () {
Build BD = new Build ();
String model = Bd. MODEL;
return model;
}
/**
* Get screen size
*
* */
public static Size Getwindowsize (context context) {
WindowManager wm = (WindowManager) context
. Getsystemservice (Context.window_service);
Size winsize = new Size (Wm.getdefaultdisplay (). GetWidth (), WM
. Getdefaultdisplay (). GetHeight ());
return winsize;
}
/**
* Get current system Month Day
*
* */
public static String GetTime () {
Time time = new Time ();
Time.settonow ();
return time.year+ "-" + (time.month+1) + "-" +time.monthday+ "-" +time.hour;
}
/**
* Get the native serial number IMEI
*
* */
public static String Getimei (context context) {
Telephonymanager Telephonymanager = (telephonymanager) context
. Getsystemservice (Context.telephony_service);
return Telephonymanager.getdeviceid ();
}
/**
* Determine if the SD card exists
*
* */
public static Boolean Existsdcard () {
if (Android.os.Environment.getExternalStorageState (). Equals (
Android.os.Environment.MEDIA_MOUNTED)) {
return true;
} else
return false;
}
/**
* SD Card remaining space
*
* */
public static long Getsdfreesize ()
{
File path = Environment.getexternalstoragedirectory ();
StatFs StatFs = new StatFs (Path.getpath ());
Get the size of a single block of data
Long blocksize = Statfs.getblocksize ();
Get the number of free data blocks
Long Freeblock = Statfs.getavailableblocks ();
Return (freeblock*blocksize)/1024/1024; Units MB
}
/**
* Total SD card capacity
*
**/
public static long Getsdallsize ()
{
File path = Environment.getexternalstoragedirectory ();
StatFs StatFs = new StatFs (Path.getpath ());
Get the size of a single block of data
Long blocksize = Statfs.getblocksize ();
Get the total number of data blocks
Long Allblock = Statfs.getblockcount ();
Return (allblock*blocksize)/1024/1024; Units MB
}
/**
* Determine if a folder exists and does not exist to create a file directory Sd/wlcache
* Return
**/
public static Boolean Existfile ()
{
File File = new file (Sd_card);
if (!file.exists ()) {
File.mkdir ();
return true;
}
return true;
}
/**
* Determine if WiFi is available turn is false no
* Return
**/
public static Boolean wifiavailable (context context)
{
Connectivitymanager manager = (Connectivitymanager) context.getsystemservice (Context.connectivity_service);
Networkinfo networkinfo = Manager.getactivenetworkinfo ();
if (networkinfo! = null && networkinfo.gettype () = = Connectivitymanager.type_wifi)
{
return true;
}
return false;
}
/**
* Determine if the GPS is open
* Return
**/
public static Boolean Existgps (context context)
{
Locationmanager Locationmanager = (locationmanager) context.getsystemservice (Context.location_service);
if (locationmanager.isproviderenabled (Android.location.LocationManager.GPS_PROVIDER))
{
return true;
}
return false;
}
/**
* Determine if the mobile network is available
* Return
**/
public static Boolean mobileavailable (context context)
{
Connectivitymanager manager = (Connectivitymanager) context.getsystemservice (Context.connectivity_service);
Networkinfo networkinfo = Manager.getactivenetworkinfo ();
if (networkinfo! = null && networkinfo.gettype () = = Connectivitymanager.type_mobile)
{
return true;
}
return false;
}
/**
* Determine if the network is available
* Return
**/
public static Boolean netavailable (context context) {
Connectivitymanager manager = (Connectivitymanager) context.getsystemservice (Context.connectivity_service);
Networkinfo networkinfo = Manager.getactivenetworkinfo ();
if (networkinfo! = null) {
return true;
}
return false;
}
/**
* Determine if the APK is the first time to start
* Return
**/
public static Boolean APKFIRSTST (context context)
{
Sharedpreferences prefs = preferencemanager.getdefaultsharedpreferences (context);
Boolean firsttime = Prefs.getboolean ("Com.vieworld.function", true);
if (firsttime) {
Editor PEdit = Prefs.edit ();
Pedit.putboolean ("Com.vieworld.function", false);
Pedit.commit ();
}
return firsttime;
}
/**
* Get the version number of the current package
* Return
**/
public static String Apkversioncode (context context)
{
Packagemanager pack = Context.getpackagemanager ();
PackageInfo packageinfo = null;
String versioncode = null;
try {
PackageInfo = Pack.getpackageinfo (Context.getpackagename (), 0);
Versioncode = Packageinfo.versionname;
} catch (Namenotfoundexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
return versioncode;
}
/**
* Determine if the APK needs to be with the new
**/
public static Boolean Isapkupdata (String versioncode,string newversioncode)
{
System.out.println (versioncode+ "=" +newversioncode);
if (Newversioncode.equals (Versioncode))
{
return true;
}
Else
return false;
}
}