首页 > 代码库 > android取国家,语言,存储大小等

android取国家,语言,存储大小等

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
private static String newUUID() {
    return UUID.randomUUID().toString();
  }
 
  private static String getLocaleCountry() {
    return java.util.Locale.getDefault().getCountry();
  }
 
  private static String getLocaleLanguage() {
    return java.util.Locale.getDefault().getLanguage();
  }
 
  private static long getTimeZoneOffset(long time) {
    // TimeZone.getOffset() returns milliseconds. We want seconds.
    return java.util.TimeZone.getDefault().getOffset(time) / 1000;
  }
 
  private static String getTimeZoneName() {
    return java.util.TimeZone.getDefault().getDisplayName(
        false, java.util.TimeZone.SHORT, java.util.Locale.getDefault());
  }
 
  private static long getFreeDiskSpace() {
    android.os.StatFs s = new android.os.StatFs(
        android.os.Environment.getDataDirectory().getAbsolutePath());
    return (long)s.getAvailableBlocks() * (long)s.getBlockSize();
  }
 
  private static long getTotalDiskSpace() {
    android.os.StatFs s = new android.os.StatFs(
        android.os.Environment.getDataDirectory().getAbsolutePath());
    return (long)s.getBlockCount() * (long)s.getBlockSize();
  }
 
  private String getPhoneNumberCountryCode() {
    try  {
      android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager)
          getSystemService(Context.TELEPHONY_SERVICE);
      try {
        return tm.getNetworkCountryIso();
      } catch (Exception e) {
        return tm.getSimCountryIso();
      }
    } catch (Exception e) {
      return java.util.Locale.getDefault().getCountry();
    }
  }