代码之家  ›  专栏  ›  技术社区  ›  Peterworks

Kotlin AAR Android库崩溃

  •  0
  • Peterworks  · 技术社区  · 7 年前

    我现在正在尝试建立AAR库以获取设备信息。 当我构建库时,这看起来很好,但是当我将测试应用程序与库集成时,我会一直崩溃。

    这是我的事故日志。

    07-07 02:44:23.033 8021-8021/ruri.sdk_test E/AndroidRuntime: FATAL EXCEPTION: main
        Process: ruri.sdk_test, PID: 8021
        java.lang.ClassCastException: java.lang.String cannot be cast to android.net.ConnectivityManager
            at jinuooki.com.peterworks.peterBrix$Companion.event(peterBrix.kt:43)
            at jinuooki.com.peterworks.peterBrix.event(Unknown Source:2)
            at ruri.sdk_test.MainActivity$1.onClick(MainActivity.java:20)
            at android.view.View.performClick(View.java:6294)
            at android.view.View$PerformClick.run(View.java:24770)
            at android.os.Handler.handleCallback(Handler.java:790)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:164)
            at android.app.ActivityThread.main(ActivityThread.java:6494)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
    

    这是我的图书馆代码。

    fun event(eventName: String) {
    
            val osName = "Android"
    
            val connect: ConnectivityManager = Context.CONNECTIVITY_SERVICE
            val netStatue = connect.activeNetworkInfo.typeName
            val networkString = netStatue.toLowerCase()
    
            val wm: WindowManager = Context.WINDOW_SERVICE
            val rotation = wm.defaultDisplay.rotation
            val sMode = when (rotation) {
                Surface.ROTATION_0 -> true
                Surface.ROTATION_180 -> true
                Surface.ROTATION_90 -> false
                Surface.ROTATION_270 -> false
                else -> null
            }
    
            val telephonyManager = Context.TELEPHONY_SERVICE
            val netwokrName = telephonyManager
    
            val app = PackageManager.GET_META_DATA as ApplicationInfo
            val bundle = app.metaData
    
            val packagename = app.packageName
    
        }
    

    你能告诉我我错过了什么吗?

    1 回复  |  直到 6 年前
        1
  •  0
  •   David Rawson B Aristide    7 年前

    String ConnectivityManager

    here

    val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager