Erhalten Sie grundlegende Informationen zu Mobiltelefonen in Android

Paket cn.wostore.android.woanalysis;

android.app.ActivityManager importieren;
android.content.Context importieren;
import android.content.pm.PackageInfo;
android.content.pm.PackageManager importieren;
android.location.Location importieren;
android.location.LocationManager importieren;
android.os.Build importieren;
android.os.Environment importieren;
android.os.StatFs importieren;
android.provider.Settings importieren;
import android.text.TextUtils;

import cn.wostore.android.util.NetworkUtil;
import cn.wostore.android.util.SystemUtil;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Random;
import java.util.UUID;

/ **

  • Werkzeuge.

  • @ Autor Chenxuliang

  • @version 1.0.0

  • @date 2017-11-7
    /
    public final class Utils { private Utils () { /

    kann nicht instanziiert werden * /
    neue UnsupportedOperationException auslösen ("kann nicht instanziiert werden");
    }}

    / **

    • / 缓存 路径
      * /
      public static String getCachePath (Kontextkontext) { String cachePath = “”; // 内部 缓存Datei cacheFile = context.getCacheDir (); if (cacheFile! = null && cacheFile.exists ()) { cachePath = cacheFile.getPath (); } return cachePath; }}







    / **

    • Holen Sie sich den Ordnerpfad zum Speichern des Absturzprotokolls
      * /
      public static String getSaveCrashInfoDir (Kontextkontext) { String saveDir = getCachePath (Kontext) + File.separator + "WoAnalysis" + File.separator + "CrashInfo"; return saveDir; }


    / **

    • Holen Sie sich den Ordnerpfad zum Speichern des Punktprotokolls
      * /
      public static String getSaveDottingInfoDir (Kontextkontext) { String saveDir = getCachePath (Kontext) + File.separator + "WoAnalysis" + File.separator + "DottingInfo"; return saveDir; }


    / **

    • Generieren Sie den Dateinamen basierend auf dem Zeitstempel
      * /
      public static String generateFileName () { String fileName = System.currentTimeMillis () + ".data"; return fileName; }


    / **

    • / 单个 文件
      * /
      public static boolean deleteFile (Zeichenfolgenpfad) { File file = new File (Pfad); if (file.isFile () && file.exists ()) { return file.delete (); } return false; }}





    / **

    • 获取 app 包 名
      * /
      public static String getAppPackageName (Kontextkontext) { String packageName = context.getPackageName (); if (TextUtils.isEmpty (packageName)) { packageName = “”; } return packageName; }}





    / **

    • 获取 应用 名
      * /
      public static String getAppName (Kontextkontext) { String name = “”; PackageManager packageManager = context.getPackageManager (); try { PackageInfo packageInfo = packageManager.getPackageInfo (context.getPackageName (), 0); name = (String) packageManager.getApplicationLabel (packageInfo.applicationInfo); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace (); } if (TextUtils.isEmpty (name)) { name = “”; } return name; }}












    / **

    • 获取 app 版本 名字
      * /
      public static String getAppVersionName (Kontextkontext) { String clientVersion = “”; PackageManager packageManager = context.getPackageManager (); try { PackageInfo packageInfo = packageManager.getPackageInfo (context.getPackageName (), 0); clientVersion = packageInfo.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace (); } return clientVersion == null? "": ClientVersion; }}









    / **

    • 获取 app 版本 号
      * /
      public static int getAppVersionCode (Kontextkontext) { int code = 0; PackageManager packageManager = context.getPackageManager (); try { PackageInfo packageInfo = packageManager.getPackageInfo (context.getPackageName (), 0); code = packageInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace (); } Rückkehrcode; }}









    / **

    • Holen Sie sich die CPU-Architektur des Mobiltelefons
      * /
      public static String getCpuABI () { return Build.CPU_ABI; }

    / **

    • Rufen Sie die Systemversionsnummer, 7.0 usw. ab.
      * /
      Public static String getOSVersion () { String str = Build.VERSION.RELEASE; if (TextUtils.isEmpty (str)) { str = “”; } return str; }





    / **

    • Holen Sie sich die Android API-Version, 24 usw.
      * /
      public static int getAndroidSDKVersion () { int num = Build.VERSION.SDK_INT; return num; }


    / **

    • Holen Sie sich die Marke des Mobiltelefons, GIONEE usw.
      * /
      public static String getBrand () { String str = Build.BRAND; if (TextUtils.isEmpty (str)) { str = “”; } return str; }





    / **

    • Telefonmodell, GN8002S usw.
      * /
      public static String getModel () { String str = Build.MODEL; if (TextUtils.isEmpty (str)) { str = “”; } return str; }





    private static final long GB = 1073741824; // 1024 * 1024 * 1024
    private static final long MB = 1048576; // 1024 * 1024
    private static final long KB = 1024;

    / **

    • Erfassung der Dateigröße
    • @param Länge Dateigröße, Einheit KB
    • @return 文件 大小 字符串
      * /
      öffentlicher statischer String getFileSize (lange Länge) { if (Länge> = GB) { return String.format ("%. 2f GB", Länge * 1.0 / GB); } else if (Länge> = MB) { return String.format ("%. 2f MB", Länge * 1,0 / MB); } else { return String.format ("%. 2f KB", Länge * 1.0 / KB); } }







    / **

    • 通过 getprop 获取 系统 信息
      * /
      public static String getSystemProperty (String propName) { String result = “”; Prozess Prozess = null; BufferedReader bufferedReader = null; try { process = Runtime.getRuntime (). exec ("getprop" + propName); } catch (IOException e) { e.printStackTrace (); } try { InputStream inputStream = process.getInputStream (); InputStreamReader inputStreamReader = neuer InputStreamReader (inputStream); bufferedReader = neuer BufferedReader (inputStreamReader, 8 * 1024); String info; while ((info = bufferedReader.readLine ())! = null) { result + = info; }}
















      } catch (IOException e) { e.printStackTrace (); } finally { if (bufferedReader! = null) { try { bufferedReader.close (); } catch (IOException e) { e.printStackTrace (); } } } Ergebnis zurückgeben; }}











    / **

    • / 网络 连接 状态
      * /
      public static String getConnectStatus (Kontextkontext) { if (NetworkUtil.isConnected (Kontext)) { if (NetworkUtil.isWifiConnected (Kontext)) { return “WIFI”; } else { return "GPRS"; } } else { return "unverbunden"; } }









    / **

    • Holen Sie sich Telefon Breite und Länge
    • Um den Längen- und Breitengrad des Telefons zu erhalten, müssen die folgenden Berechtigungen hinzugefügt werden
    • @param Kontext
    • @return
      * /
      public static Location getLocation (Kontextkontext) { // Standortmanager abrufen LocationManager locationManager = (LocationManager) context.getSystemService (Context.LOCATION_SERVICE); // Alle verfügbaren Standortanbieter abrufen List provider = locationManager.getProviders (true); String locationProvider; if (providers.contains (LocationManager.GPS_PROVIDER)) { // Wenn es sich um GPS locationProvider = LocationManager.GPS_PROVIDER handelt; } else if (providers.contains (LocationManager.NETWORK_PROVIDER)) { // Wenn es Network locationProider ist = LocationManager.NETWORK_PROVIDER; } else { return null; } // Standort abrufen Location location = null;
















      try { location = locationManager.getLastKnownLocation (locationProvider); } catch (Ausnahme e) { e.printStackTrace (); } return location; }}





    / **

    • RAM 总 的 内存 (RAM)
      * /
      öffentlicher statischer String getMemoryTotal (Kontextkontext) { ActivityManager am = (ActivityManager) context.getSystemService (Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo (); am.getMemoryInfo (mi); return Utils.getFileSize (mi.totalMem); }}




    / **

    • RAM 可用 的 内存 (RAM)
      * /
      öffentlicher statischer String getMemoryFree (Kontextkontext) { ActivityManager am = (ActivityManager) context.getSystemService (Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo (); am.getMemoryInfo (mi); return Utils.getFileSize (mi.availMem); }}




    / **

    • 获得 SD 卡 总 大小
      * /
      public static String getSDTotalSize () { Dateipfad = Environment.getExternalStorageDirectory (); StatFs stat = neue StatFs (path.getPath ()); long blockSize = stat.getBlockSize (); long totalBlocks = stat.getBlockCount (); return getFileSize (blockSize * totalBlocks); }}





    / **

    • / Sd 卡 剩余 容量 , 即可 用 大小
      * /
      public static String getSDAvailableSize () { Dateipfad = Environment.getExternalStorageDirectory (); StatFs stat = neue StatFs (path.getPath ()); long blockSize = stat.getBlockSize (); long availableBlocks = stat.getAvailableBlocks (); return getFileSize (blockSize * availableBlocks); }}





    / **

    • / 机身 内存 总 大小
      * /
      public static String getRomTotalSize () { Dateipfad = Environment.getDataDirectory (); StatFs stat = neue StatFs (path.getPath ()); long blockSize = stat.getBlockSize (); long totalBlocks = stat.getBlockCount (); return getFileSize (blockSize * totalBlocks); }}





    / **

    • / 机身 可用 内存
      * /
      public static String getRomAvailableSize () { Dateipfad = Environment.getDataDirectory (); StatFs stat = neue StatFs (path.getPath ()); long blockSize = stat.getBlockSize (); long availableBlocks = stat.getAvailableBlocks (); return getFileSize (blockSize * availableBlocks); }}





    / **

    • Ruft den aktuellen Threadnamen ab
      * /
      public static String getCurrentThreadName () { return Thread.currentThread (). GetName (); }

    / **

    • Ruft die aktuelle Thread-ID ab
      * /
      public static long getCurrentThreadId () { return Thread.currentThread (). GetId (); }

    / **

    • Ruft den aktuellen Prozessnamen ab
      * /
      public static String getCurrentProcessName () { return getProcessName (android.os.Process.myPid ()); }

    / **

    • Rufen Sie den Prozessnamen ab, der der Prozessnummer entspricht
    • @param pid Prozessnummer
    • @return 进程 名
      * /
      public static String getProcessName (int pid) { BufferedReader reader = null; try { reader = new BufferedReader (neuer FileReader ("/ proc /" + pid + "/ cmdline")); String processName = reader.readLine (); if (! TextUtils.isEmpty (processName)) { processName = processName.trim (); } return processName; } catch (Throwable throwable) { throwable.printStackTrace (); } endlich { try { if (reader! = null) { reader.close (); } } catch (IOException-Ausnahme) { exception.printStackTrace (); } } return “”;




















      }}

    / **

    • Holen Sie sich eine UUID
    • @return String UUID
      * /
      public static String getUUID () { String uuid = UUID.randomUUID (). toString (); // 去掉 “-” 符号return uuid.replaceAll ("-", "”); }}



    / **

    • Zufallszahl abrufen
      * /
      public static int getRandomInt () { Random random = new Random (); int num = random.nextInt (90000) + 10000; return num; }



    /// **
    // * 获取 手机 deviceId
    // /
    // public static String getDeviceId (Kontextkontext) { // String deviceId = “”; // TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService (Context.TELEPHONY_SERVICE); // if (telephonyManager! = null) { // try { // deviceId = telephonyManager.getDeviceId (); //} catch (Ausnahme e) { // e.printStackTrace (); //} //} // return deviceId; //} // ///












    *
    // * 获取 手机 macAddress
    // * /
    // öffentlicher statischer String getMacAddress (Kontextkontext) { // String macAddress = “”;

    // WifiManager wifi = (WifiManager) context.getSystemService (Context.WIFI_SERVICE);
    // if (wifi! = null) { // WifiInfo info = wifi.getConnectionInfo (); // if (info! = null) { // macAddress = info.getMacAddress (); //} //} // return macAddress; //}






    / **

    • 获取 手机 androidId
      * /
      public static String getAndroidId (Kontextkontext) { String androidId = “”; try { androidId = Settings.Secure.getString (context.getContentResolver (), Settings.Secure.ANDROID_ID); } catch (Ausnahme e) { e.printStackTrace (); } return androidId; }}







    / **

    • 获取 手机 SerialNumber
      * /
      public static String getSerialNumber () { return Build.SERIAL; }}

    / **

    • * 手机 唯一 id
      * /
      public static String getDeviceUniqueId (Kontextkontext) { String androidId = getAndroidId (Kontext); String serialNumber = getSerialNumber (); if (TextUtils.isEmpty (androidId)) { androidId = “”; } if (TextUtils.isEmpty (serialNumber)) { serialNumber = “”; } String uniqueId = androidId + serialNumber; if (TextUtils.isEmpty (uniqueId)) { uniqueId = SystemUtil.getImei (Kontext); } if (TextUtils.isEmpty (uniqueId)) { uniqueId = “”; } return uniqueId; }}
















    / **

    • CORE-VER
    • Kernelversion
    • return String
      * /

    öffentlicher statischer String getLinuxCore_Ver () { Process process = null; String kernelVersion = “”; try { process = Runtime.getRuntime (). exec ("cat / proc / version"); } catch (IOException e) { // TODO Automatisch generierter catch-Block e.printStackTrace (); }}







     // get the output line
     InputStream outs = process.getInputStream();
     InputStreamReader isrout = new InputStreamReader(outs);
     BufferedReader brout = new BufferedReader(isrout, 8 * 1024);
    
    
     String result = "";
     String line;
     try {
         while ((line = brout.readLine()) != null) {
             result += line;
         }
     } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
     } finally {
         try {
             if (brout != null) {
                 brout.close();
             }
             if (isrout != null) {
                 isrout.close();
             }
             if (outs != null) {
                 outs.close();
             }
         } catch (IOException e) {
             e.printStackTrace();
         }
     }
    
     try {
         if (result != "") {
             String Keyword = "version ";
             int index = result.indexOf(Keyword);
             line = result.substring(index + Keyword.length());
             index = line.indexOf(" ");
             kernelVersion = line.substring(0, index);
         }
     } catch (IndexOutOfBoundsException e) {
         e.printStackTrace();
     }
     return kernelVersion;
    

    }
    }

Ich denke du magst

Origin blog.csdn.net/weixin_45361581/article/details/109647348
Empfohlen
Rangfolge