miaowmiaow / fragmject

fragmject is a learning project prepared for Kotlin and Jetpack Compose. | fragmject 是一个为初学者准备的上手项目。 通过对 Kotlin 和 Compose 的系统运用,实现的一个功能完备符合主流市场标准 App。 fragmject 没有复杂的业务和多余的封装, 完全依照 Android Developer 官方的写法。 代码简单,内容全面,快速上手,对理解其他项目设计思想和封装技巧也很有帮助。
Apache License 2.0
1.32k stars 233 forks source link

大佬,可以把如下方法集成到 SystemHelper中吗 #17

Closed yuwaixingtian closed 1 year ago

yuwaixingtian commented 1 year ago

如题,不太清楚为什么com.example.miaow.base.utils.SystemHelper 这个类中的 Context.getVersionName 等方法在需要使用到 Context 的地方居然可以省略掉,我查找了整个项目没有发现 packageManager 首字母小写的其他类似 var,val的申明关键词,没想到作者您是写法居然可以使用。所以想知道下面提供的两个获取系统IP的方法能否集成进这个系统类中: //获取外网IP suspend fun getPublicIP(): String { val response: HttpResponse = client.get("https://api.ipify.org") var publicIP = try { response.bodyAsText() } catch (e: Exception) { e.printStackTrace() e.toString() } return publicIP }

//获取局域网IP fun getIpAddress(context: Context): String { val wifiManager = context.getSystemService(Context.WIFI_SERVICE) as WifiManager val ip = Formatter.formatIpAddress(wifiManager.connectionInfo.ipAddress) return ip } 非常感谢大佬!麻烦啦~

miaowmiaow commented 1 year ago

` //获取局域网IP fun getIpAddress(context: Context): String { val wifiManager = context.getSystemService(Context.WIFI_SERVICE) as WifiManager val ip = Formatter.formatIpAddress(wifiManager.connectionInfo.ipAddress) return ip }

//获取局域网IP(改造后) fun Context.getIpAddress(): String { val wifiManager = getSystemService(Context.WIFI_SERVICE) as WifiManager val ip = Formatter.formatIpAddress(wifiManager.connectionInfo.ipAddress) return ip } ` 你对比下代码就能发现区别,属于kotlin的语法糖之一

非Bug问题可以加群交流,写Issuse效率慢且容易让人误解

yuwaixingtian commented 1 year ago

` //获取局域网IP fun getIpAddress(context: Context): String { val wifiManager = context.getSystemService(Context.WIFI_SERVICE) as WifiManager val ip = Formatter.formatIpAddress(wifiManager.connectionInfo.ipAddress) return ip }

//获取局域网IP(改造后) fun Context.getIpAddress(): String { val wifiManager = getSystemService(Context.WIFI_SERVICE) as WifiManager val ip = Formatter.formatIpAddress(wifiManager.connectionInfo.ipAddress) return ip } ` 你对比下代码就能发现区别,属于kotlin的语法糖之一

非Bug问题可以加群交流,写Issuse效率慢且容易让人误解

哈哈哈哈哈,懂了懂了,我就说怎么提交两天一直刷新没看见回复,谢谢大佬