类型常用工具方法,APk管理等等的主意

时间:2019-09-18 15:50来源: 操作系统
// 获取手提式有线电话机型号 猎取Android开机运维列表 /** * 获取Android开机启动列表 */private static final String RECEIVE_BOOT_COMPLETED = "android.permission.RECEIVE_BOOT_COMPLETED";private static final String ACT

// 获取手提式有线电话机型号

猎取Android开机运维列表

/**
 * 获取Android开机启动列表
 */
private static final String RECEIVE_BOOT_COMPLETED = "android.permission.RECEIVE_BOOT_COMPLETED";
private static final String ACTION_BOOT_COMPLETED = "android.permission.ACTION_BOOT_COMPLETED";

public static List<AutoStartInfo> fetchInstalledApps(Context mContext) {
    PackageManager pm = mContext.getPackageManager();
    List<ApplicationInfo> appInfo = pm.getInstalledApplications(0);
    Iterator<ApplicationInfo> appInfoIterator = appInfo.iterator();
    List<AutoStartInfo> appList = new ArrayList<AutoStartInfo>(
            appInfo.size());

    while (appInfoIterator.hasNext()) {
        ApplicationInfo app = appInfoIterator.next();
        int flag = pm.checkPermission(RECEIVE_BOOT_COMPLETED,
                app.packageName);
        if (flag == PackageManager.PERMISSION_GRANTED) {
            AutoStartInfo appMap = new AutoStartInfo();
            String label = pm.getApplicationLabel(app).toString();
            Drawable icon = pm.getApplicationIcon(app);
            String packageName = app.packageName;
            if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                appMap.setSystem(true);
                // abAppProcessInfo.isSystem = true;
            } else {
                appMap.setSystem(false);
                // abAppProcessInfo.isSystem = false;
            }

            // appMap.setDesc(desc);
            appMap.setIcon(icon);
            appMap.setPackageName(packageName);
            appMap.setLabel(label);

            appList.add(appMap);
        }
    }
    return appList;
}
public static String getInfo() {Build bd = new Build();String model = bd.MODEL;return model;}

获得自启应用

/**
 * 获取自启应用
 * 
 * @param mContext
 * @return
 */

public static List<AutoStartInfo> fetchAutoApps(Context mContext) {
    PackageManager pm = mContext.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED);

    List<ResolveInfo> resolveInfoList = pm.queryBroadcastReceivers(intent,
            PackageManager.GET_DISABLED_COMPONENTS);
    List<AutoStartInfo> appList = new ArrayList<AutoStartInfo>();
    // 得到的参数
    String appName = null;
    String packageReceiver = null;
    Drawable icon = null;
    boolean isSystem = false;
    boolean isenable = true;
    String packageName = null;
    boolean isAutoStart = false;
    boolean isBackStart = false;
    /**
     * 通过 PackageInfo 获取具体信息方法:
     * 
     * 包名获取方法:packageInfo.packageName
     * icon获取获取方法:packageManager.getApplicationIcon(applicationInfo)
     * 应用名称获取方法:packageManager.getApplicationLabel(applicationInfo)
     * 使用权限获取方法:packageManager.getPackageInfo(packageName,PackageManager.
     * GET_PERMISSIONS) .requestedPermissions
     * 
     * 通过 ResolveInfo 获取具体信息方法:
     * 
     * 包名获取方法:resolve.activityInfo.packageName
     * icon获取获取方法:resolve.loadIcon(packageManager)
     * 应用名称获取方法:resolve.loadLabel(packageManager).toString()
     * 
     */
    if (resolveInfoList.size() > 0) {
        for (int i = 0; resolveInfoList.size() > i; i++) {
            isAutoStart = false;
            isBackStart = false;
            /**
             * // 查找安装的package是否有开机启动权限 if(PackageManager.PERMISSION_GRANTED
             * == context
             * .getPackageManager().checkPermission(BOOT_START_PERMISSION,
             * app.packageName))
             * 
             * BOOT_COMPLETED BOOT_START_PERMISSION RECEIVE_BOOT_COMPLETED
             * ACTION_BOOT_COMPLETED
             */
            if (mContext.getPackageManager().checkPermission(
                    RECEIVE_BOOT_COMPLETED,
                    resolveInfoList.get(i).activityInfo.packageName) == PackageManager.PERMISSION_GRANTED) {
                isAutoStart = true;
            }
            if (mContext.getPackageManager().checkPermission(
                    ACTION_BOOT_COMPLETED,
                    resolveInfoList.get(i).activityInfo.packageName) == PackageManager.PERMISSION_GRANTED) {
                isBackStart = true;
            }
            appName = resolveInfoList.get(i).loadLabel(pm).toString();
            packageName = resolveInfoList.get(i).activityInfo.packageName;
            packageReceiver = resolveInfoList.get(i).activityInfo.packageName
                    + "/" + resolveInfoList.get(i).activityInfo.name;
            icon = resolveInfoList.get(i).loadIcon(pm);
            ComponentName mComponentName2 = new ComponentName(
                    resolveInfoList.get(i).activityInfo.packageName,
                    resolveInfoList.get(i).activityInfo.name);
            if (pm.getComponentEnabledSetting(mComponentName2) == 2) {
                isenable = false;
            } else {
                isenable = true;
            }
            if ((resolveInfoList.get(i).activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                isSystem = true;
            } else {
                isSystem = false;
            }
            //
            AutoStartInfo mAutoStartInfo = new AutoStartInfo();
            mAutoStartInfo.setLabel(appName);
            mAutoStartInfo.setSystem(isSystem);
            mAutoStartInfo.setEnable(isenable);
            mAutoStartInfo.setIcon(icon);
            mAutoStartInfo.setPackageName(packageName);
            mAutoStartInfo.setPackageReceiver(packageReceiver);
            mAutoStartInfo.setAutoStart(isAutoStart);
            mAutoStartInfo.setBackStart(isBackStart);
            boolean isAdd = true;
            if (appList != null) {
                for (int j = 0; appList.size() > j; j++) {
                    if (appList.get(j).getPackageName().equals(packageName)) {
                        isAdd = false;
                    }
                }
            }
            if (isAdd) {
                appList.add(mAutoStartInfo);
            }
        }

    }

    return appList;
}

/**

单位转换

/**
 * 单位转换
 * 
 * @param length
 * @return
 */

public static String toSize(double length) {
    long kb = 1024;
    long mb = 1024 * kb;
    long gb = 1024 * mb;
    if (length < kb) {
        return String.format("%d B", (int) length);
    } else if (length < mb) {
        return String.format("%.2f KB", length / kb);

    } else if (length < gb) {
        return String.format("%.2f MB", length / mb);

    } else {
        return String.format("%.2f GB", length / gb);

    }

}

// storage, G M K B
public static String convertStorage(long size) {
    long kb = 1024;
    long mb = kb * 1024;
    long gb = mb * 1024;

    if (size >= gb) {
        return String.format("%.1f GB", (float) size / gb);
    } else if (size >= mb) {
        float f = (float) size / mb;
        return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f);
    } else if (size >= kb) {
        float f = (float) size / kb;
        return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f);
    } else
        return String.format("%d B", size);
}

public static StorageSize convertStorageSize(long size) {
    long kb = 1024;
    long mb = kb * 1024;
    long gb = mb * 1024;
    StorageSize sto = new StorageSize();
    if (size >= gb) {

        sto.suffix = "GB";
        sto.value = (float) size / gb;
        return sto;
    } else if (size >= mb) {

        sto.suffix = "MB";
        sto.value = (float) size / mb;

        return sto;
    } else if (size >= kb) {

        sto.suffix = "KB";
        sto.value = (float) size / kb;

        return sto;
    } else {
        sto.suffix = "B";
        sto.value = (float) size;

        return sto;
    }

}
  • 收获显示屏尺寸大小
    • */

获取SD卡信息

public static SDCardInfo getSDCardInfo() {
    // String sDcString = Environment.getExternalStorageState();

    if (Environment.isExternalStorageRemovable()) {
        String sDcString = Environment.getExternalStorageState();
        if (sDcString.equals(Environment.MEDIA_MOUNTED)) {
            File pathFile = Environment.getExternalStorageDirectory();

            try {
                StatFs statfs = new StatFs(pathFile.getPath());

                // 获取SDCard上BLOCK总数
                long nTotalBlocks = statfs.getBlockCount();

                // 获取SDCard上每个block的SIZE
                long nBlocSize = statfs.getBlockSize();

                // 获取可供程序使用的Block的数量
                long nAvailaBlock = statfs.getAvailableBlocks();

                // 获取剩下的所有Block的数量(包括预留的一般程序无法使用的块)
                long nFreeBlock = statfs.getFreeBlocks();

                SDCardInfo info = new SDCardInfo();
                // 计算SDCard 总容量大小MB
                info.total = nTotalBlocks * nBlocSize;

                // 计算 SDCard 剩余大小MB
                info.free = nAvailaBlock * nBlocSize;

                return info;
            } catch (IllegalArgumentException e) {

            }
        }
    }
    return null;
}
/**
 * data 目录 getDataDirectory()
 * 
 * @param context
 * @return
 */
public static SDCardInfo getSystemSpaceInfo(Context context) {
    File path = Environment.getDataDirectory();
    // File path = context.getCacheDir().getAbsoluteFile();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    long availableBlocks = stat.getAvailableBlocks();

    long totalSize = blockSize * totalBlocks;
    long availSize = availableBlocks * blockSize;
    SDCardInfo info = new SDCardInfo();
    info.total = totalSize;
    info.free = availSize;
    return info;

}

public static SDCardInfo getRootSpaceInfo() {
    File path = Environment.getRootDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    long availableBlocks = stat.getAvailableBlocks();

    long totalSize = blockSize * totalBlocks;
    long availSize = availableBlocks * blockSize;
    // 获取SDCard上每个block的SIZE
    long nBlocSize = stat.getBlockSize();

    SDCardInfo info = new SDCardInfo();
    // 计算SDCard 总容量大小MB
    info.total = totalSize;

    // 计算 SDCard 剩余大小MB
    info.free = availSize;
    return info;

}

沐浴状态栏

public void sethah(Window window) {
    if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
        // 透明状态栏
        // getWindow.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        // 透明导航栏
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }
}
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;}

检查当前网络是还是不是可用

 /**
 * 检查当前网络是否可用
 * 
 * @param activity
 * @return
 */
public boolean isNetworkAvailable(Activity activity) {
    Context context = activity.getApplicationContext();
    // 获取手机所有连接管理对象(包括对Wifi,net等连接的管理)
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager == null) {
        return false;
    } else {
        // 获取NetworkInfo对象
        NetworkInfo[] networkInfo = connectivityManager.getAllNetworkInfo();
        if (networkInfo != null && networkInfo.length > 0) {
            for (int i = 0; i < networkInfo.length; i++) {
                System.out.println(i + "===state==="
                        + networkInfo[i].getState());
                System.out.println(i + "===style==="
                        + networkInfo[i].getTypeName());
                // 判断当前网络状态是否为连接状态
                if (networkInfo[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
    }
    return false;
}

/**

安装APK

/**
 * 安装APK
 * 
 * @param context
 * @param packageName
 */
public void update(Context context, String packageName) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(Environment
            .getExternalStorageDirectory(), packageName)),
            "application/vnd.android.package-archive");
    context.startActivity(intent);
}
  • 收获当前系统年月日
    • */

看清有些程序是不是安装在手机中

/**
 * 判断某个程序是否安装在手机中
 * 
 * @param context
 *            上下文
 * @param packageName
 *            需要验证的包名
 * @return 是否安装
 */
public static boolean isPackageExist(Context context, String packageName) {
    if (packageName == null)
        return false;
    boolean packageExist = false;
    PackageManager packageManager = context.getPackageManager();
    try {
        packageManager.getPackageInfo(packageName, 0);
        packageExist = true;
    } catch (PackageManager.NameNotFoundException ignored) {
        // L.d("isPackageExist:" + ignored);
    }
    return packageExist;
}

推断APK是或不是已安装

  /**
 * 判断APK是否已安装
 * 
 * @param pm
 * @param packageName
 * @param versionCode
 * @return
 */
public int doType(PackageManager pm, String packageName, int versionCode) {
    List<PackageInfo> pakageinfos = pm
            .getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
    for (PackageInfo pi : pakageinfos) {
        String pi_packageName = pi.packageName;
        int pi_versionCode = pi.versionCode;
        // 如果这个包名在系统已经安装过的应用中存在
        if (packageName.endsWith(pi_packageName)) {
            // Log.i("test","此应用安装过了");
            if (versionCode == pi_versionCode) {
                Log.i("test", "已经安装,不用更新,可以卸载该应用");
                return 1000;
            } else if (versionCode > pi_versionCode) {
                Log.i("test", "已经安装,有更新");
                return 2000;
            }
        }
    }
    Log.i("test", "未安装该应用,可以安装");
    return 3000;
}
public static String getTime() {Time time = new Time();time.setToNow(); return time.year+"-"+(time.month+1)+"-"+time.monthDay+"-"+time.hour;}

收获当前版本的版本名字

/**
 * 获取当前版本的版本名字
 * 
 * @param context
 * @return
 */
public String getVersion(Context context) {
    try {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(
                context.getPackageName(), 0);
        return packageInfo.versionName;
    } catch (Exception e) {
        e.printStackTrace();
        return context.getResources()
                .getString(R.string.unknown_versionnum);
    }
}

/**

获得当前版本的版本号

  /**
 * 获取当前版本的版本号
 * 
 * @return
 */
public int getVersiontheCode(Context context) {
    try {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(
                context.getPackageName(), 0);
        return packageInfo.versionCode;
    } catch (Exception e) {
        e.printStackTrace();
        return R.string.unknown_versionnum;
    }
}
  • 获取本机串号imei
    • */

认清WIFI是不是连接

/ **
 * 判断WIFI是否连接
 * 
 * @param context
 * @return true为已连接
 */
boolean isWifi = false;

public static boolean isWifiConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetworkInfo = connectivityManager
            .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetworkInfo.isConnected()) {
        return true;
    }
    return false;
}

去除单个文件

  ` /**
 * 删除单个文件
 * 
 * @param filePath
 *            被删除文件的文件名
 * @return 文件删除成功返回true,否则返回false
 */
public boolean deleteFile(String filePath, Context context) {
    File file = new File(filePath);
    if (file.isFile() && file.exists()) {
        boolean isOK = file.delete();
        scanFile(file, context);
        return isOK;
    } else {
        Toast.makeText(context, "null", 0).show();
    }
    return false;
}` 
public static String getIMEI(Context context) {TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);return telephonyManager.getDeviceId();}

扫描文件

 /**
 * 扫描文件
 * 
 * @param file
 * @param context
 */

public void scanFile(File file, Context context) {
    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    Uri uri = Uri.fromFile(file);
    intent.setData(uri);
    context.sendBroadcast(intent);
}
 /**
 * get,set
 */
private List<APKInfo> myFiles = new ArrayList<APKInfo>();

public List<APKInfo> getMyFiles() {
    return myFiles;
}

public void setMyFiles(List<APKInfo> myFiles) {
    this.myFiles = myFiles;
}

/**

采纳递归的思维,递归去找各种目录下边包车型大巴apk文件

/**
 * 运用递归的思想,递归去找每个目录下面的apk文件
 * 
 * @param file
 */
public void FindAllAPKFile(File file, Context context) {

    // 手机上的文件,目前只判断SD卡上的APK文件
    // file = Environment.getDataDirectory();
    // SD卡上的文件目录
    if (file.isFile()) {
        String name_s = file.getName();
        APKInfo myFile = new APKInfo();
        String apk_path = null;
        // MimeTypeMap.getSingleton()
        if (name_s.toLowerCase().endsWith(".apk")) {
            apk_path = file.getAbsolutePath();// apk文件的绝对路劲
            // System.out.println("----" + file.getAbsolutePath() + "" +
            // name_s);
            PackageManager pm = context.getPackageManager();
            PackageInfo packageInfo = pm.getPackageArchiveInfo(apk_path,
                    PackageManager.GET_ACTIVITIES);
            ApplicationInfo appInfo = packageInfo.applicationInfo;

            /** 获取apk的图标 */
            appInfo.sourceDir = apk_path;
            appInfo.publicSourceDir = apk_path;
            Drawable apk_icon = appInfo.loadIcon(pm);
            myFile.setIcon(apk_icon);
            /** 得到包名 */
            String packageName = packageInfo.packageName;
            myFile.setName(packageName);
            /** apk的绝对路劲 */
            myFile.setPath(file.getAbsolutePath());
            /** apk的版本名称 String */
            String versionName = packageInfo.versionName;
            myFile.setVersionName(versionName);
            /** apk的版本号码 int */
            int versionCode = packageInfo.versionCode;
            myFile.setVersionCode(versionCode);
            /** 安装处理类型 */
            int type = doType(pm, packageName, versionCode);
            myFile.setType(type);

            Log.i("ok", "处理类型:" + String.valueOf(type) + "n"
                    + "------------------我是纯洁的分割线-------------------");
            myFiles.add(myFile);
        }
        // String apk_app = name_s.substring(name_s.lastIndexOf("."));
    } else {
        File[] files = file.listFiles();
        if (files != null && files.length > 0) {
            for (File file_str : files) {
                FindAllAPKFile(file_str, context);
            }
        }
    }
}
  • 认清microSD闪存卡是还是不是存在
    • */

获取全数的应用程序音讯

/**
 * 获得所有的应用程序信息
 * 
 * @return
 */

public static List<AppBean> getAllApps(Context context) {

    PackageManager pm = context.getPackageManager();

    List<PackageInfo> packages = pm.getInstalledPackages(0);

    List<AppBean> list = new ArrayList<AppBean>();

    for (PackageInfo info : packages) {

        ApplicationInfo applicationInfo = info.applicationInfo;
        String name = applicationInfo.loadLabel(pm).toString();
        Drawable icon = applicationInfo.loadIcon(pm);

        String sourceDir = applicationInfo.sourceDir;
        File file = new File(sourceDir);

        int flags = applicationInfo.flags;
        boolean isInstallSD = false;
        if ((flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == ApplicationInfo.FLAG_EXTERNAL_STORAGE) {
            isInstallSD = true;
        }

        boolean isSystem = false;
        if ((flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM) {
            isSystem = true;
        }

        AppBean bean = new AppBean();
        bean.icon = icon;
        bean.name = name;
        bean.size = file.length();
        bean.isInstallSD = isInstallSD;
        bean.isSystem = isSystem;
        bean.packageName = info.packageName;

        list.add(bean);
    }

    return list;

}

public static List<AppBean> getAllLaunchApps(Context context) {

    PackageManager pm = context.getPackageManager();

    List<PackageInfo> packages = pm.getInstalledPackages(0);

    List<AppBean> list = new ArrayList<AppBean>();

    for (PackageInfo info : packages) {

        Intent intent = pm.getLaunchIntentForPackage(info.packageName);

        if (intent == null) {

            continue;
        }

        ApplicationInfo applicationInfo = info.applicationInfo;
        String name = applicationInfo.loadLabel(pm).toString();
        Drawable icon = applicationInfo.loadIcon(pm);

        String sourceDir = applicationInfo.sourceDir;
        File file = new File(sourceDir);

        int flags = applicationInfo.flags;
        boolean isInstallSD = false;
        if ((flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == ApplicationInfo.FLAG_EXTERNAL_STORAGE) {
            isInstallSD = true;
        }

        boolean isSystem = false;
        if ((flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM) {
            isSystem = true;
        }

        AppBean bean = new AppBean();
        bean.icon = icon;
        bean.name = name;
        bean.size = file.length();
        bean.isInstallSD = isInstallSD;
        bean.isSystem = isSystem;
        bean.packageName = info.packageName;

        list.add(bean);
    }

    return list;

}
public static boolean ExistSDCard() {if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {return true;} elsereturn false;}

/**

  • miniSD闪存卡剩余空间
    • */
public static long getSDFreeSize(){File path = Environment.getExternalStorageDirectory();StatFs statfs = new StatFs(path.getPath;//获得单个数据块的大小long blocksize = statfs.getBlockSize();//获得空闲数据块的个数long freeblock = statfs.getAvailableBlocks();return (freeblock*blocksize)/1024/1024; //单位MB}

/**

- PCIe闪存卡总体积

**/

public static long getSDALLsize(){File path = Environment.getExternalStorageDirectory();StatFs statfs = new StatFs(path.getPath;//获得单个数据块的大小long blocksize = statfs.getBlockSize();//获得全部数据块的个数long allBlock = statfs.getBlockCount();return (allBlock*blocksize)/1024/1024; //单位MB}

/**

  • 认清文件夹是或不是存在,不设有就创设文件目录SD/wlcache
  • return**/
public static boolean ExistFile(){File file = new File;if (!file.exists {file.mkdir();return true;}return true;}

/**

  • 剖断wifi是还是不是可用 turn 是 false 否
  • 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;}

/**

  • 看清GPS是还是不是张开
  • 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;}

/**

  • 决断移动互联网是或不是可用
  • 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;}

/**

  • 看清网络是还是不是可用
  • 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;}

/**

  • 推断apk是或不是是第叁次运维
  • return**/
public static boolean APKFirstSt(Context context){SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences;boolean firstTime = prefs.getBoolean("com.vieworld.function", true);if (firstTime){Editor pEdit = prefs.edit();pEdit.putBoolean("com.vieworld.function", false);pEdit.commit();}return firstTime;}

/**

  • 收获当前包的本子号
  • return**/
public static String ApkVersionCode(Context context){PackageManager pack = context.getPackageManager();PackageInfo packageInfo = null;String versionCode = null;try {packageInfo = pack.getPackageInfo(context.getPackageName;versionCode = packageInfo.versionName;} catch (NameNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}return versionCode;}

/**

  • 剖断apk是否须要更新**/
public static boolean IsApkUpdata(String versionCode,String newversionCode){System.out.println(versionCode+"="+newversionCode);if(newversionCode.equals(versionCode )){return true;}elsereturn false;}

编辑: 操作系统 本文来源:类型常用工具方法,APk管理等等的主意

关键词:

  • 上一篇:没有了
  • 下一篇:没有了