Commit e0f31f6f authored by 赵鹏翔's avatar 赵鹏翔

update file

parent 290ba320
......@@ -13,6 +13,7 @@ import com.miya.fastcashier.beans.SelfCashierAccountInfo;
import com.miya.fastcashier.databinding.DialogSystemParameterBinding;
import com.miya.fastcashier.service.AccountService;
import com.miya.fastcashier.service.LoginService;
import com.miya.fastcashier.utils.BaseFunctionKt;
import com.miya.print.PrinterManager;
import androidx.annotation.NonNull;
......@@ -35,7 +36,7 @@ public class SystemParameterDialog extends Dialog {
private void init() {
SelfCashierAccountInfo accountInfo = AccountService.INSTANCE.getAccountInfo();
// setInfo(viewBinding.tvVersion, BaseFunctionKt.getVersion(getContext()));
setInfo(viewBinding.tvVersion, BaseFunctionKt.getVersion(getContext()));
setInfo(viewBinding.tvStoreName, accountInfo.getShopInfo().getStoreName());
setInfo(viewBinding.tvStoreNum, accountInfo.getShopInfo().getStoreId());
setInfo(viewBinding.tvMerchantNum, accountInfo.getShopInfo().getHhMerchant());
......@@ -44,8 +45,8 @@ public class SystemParameterDialog extends Dialog {
setInfo(viewBinding.tvVersionType, "fastCashier_" + BuildConfig.appType);
setInfo(viewBinding.tvEquipment, "sunmi_v2pro");
setInfo(viewBinding.tvServerUrl, LoginService.Companion.getBaseUrl());
// setInfo(viewBinding.tvWifiName, BaseFunctionKt.getWifyName(getContext()));
// setInfo(viewBinding.tvNetIp, BaseFunctionKt.getNetIp(getContext()) == null ? "未知" : BaseFunctionKt.getNetIp(getContext()));
setInfo(viewBinding.tvWifiName, BaseFunctionKt.getWifyName(getContext()));
setInfo(viewBinding.tvNetIp, BaseFunctionKt.getNetIp(getContext()) == null ? "未知" : BaseFunctionKt.getNetIp(getContext()));
setInfo(viewBinding.tvPrintType, PrinterManager.getInstance().getPrinter() == null ?
getContext().getResources().getString(R.string.app_unkown) :
PrinterManager.getInstance().getPrinter().getPrinterName());
......
package com.miya.fastcashier.utils
import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.net.ConnectivityManager
import android.net.NetworkInfo
import android.net.wifi.WifiInfo
import android.net.wifi.WifiManager
import android.text.TextUtils
import java.net.Inet4Address
import java.net.NetworkInterface
import java.net.SocketException
fun isEmpty(s: String?): Boolean {
return TextUtils.isEmpty(s)
......@@ -23,3 +32,73 @@ fun dp2px(context: Context, dpValue: Float): Int {
val scale = context.resources.displayMetrics.density
return (dpValue * scale + 0.5f).toInt()
}
fun getNetIp(c: Context): String? {
val info =
(c.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).activeNetworkInfo
if (info != null && info.isConnected) {
if (info.type == ConnectivityManager.TYPE_MOBILE) { //当前使用2G/3G/4G网络
try {
//Enumeration<NetworkInterface> en=NetworkInterface.getNetworkInterfaces();
val en = NetworkInterface.getNetworkInterfaces()
while (en.hasMoreElements()) {
val intf = en.nextElement()
val enumIpAddr = intf.inetAddresses
while (enumIpAddr.hasMoreElements()) {
val inetAddress = enumIpAddr.nextElement()
if (!inetAddress.isLoopbackAddress && inetAddress is Inet4Address) {
return inetAddress.getHostAddress()
}
}
}
} catch (e: SocketException) {
e.printStackTrace()
}
} else if (info.type == ConnectivityManager.TYPE_WIFI) { //当前使用无线网络
val wifiManager = c.getSystemService(Context.WIFI_SERVICE) as WifiManager
val wifiInfo = wifiManager.connectionInfo
return intIP2StringIP(wifiInfo.ipAddress) //得到IPV4地址
}
} else {
//当前无网络连接,请在设置中打开网络
}
return null
}
/**
* 将得到的int类型的IP转换为String类型
*
* @param ip
* @return
*/
fun intIP2StringIP(ip: Int): String? {
return (ip and 0xFF).toString() + "." +
(ip shr 8 and 0xFF) + "." +
(ip shr 16 and 0xFF) + "." +
(ip shr 24 and 0xFF)
}
/**
* 获取wifi名称(即ssid)
*
* @param c
* @return
*/
fun getWifyName(c: Context): String? {
val mWifiManager = c.getSystemService(Context.WIFI_SERVICE) as WifiManager
return mWifiManager.connectionInfo.ssid
}
fun getVersion(context: Context): String? {
val packageManager = context.packageManager
val packageInfo: PackageInfo
var version = ""
try {
packageInfo = packageManager.getPackageInfo(context.packageName, 0)
version = "${packageInfo.versionCode}_v${packageInfo.versionName}"
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
}
return version
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment