我正在尝试在应用程序中挂载.obb文件,就像在代码的早期版本中所做的那样,但是由于某些原因,我无法在正常运行时调用onObbStateChange()
。
问题是,在调试器上逐步调试时,它运行得非常好!如果我在mountObb()
命令和Log.i("MigrationUtil", "onObbStateChanged")
命令中设置了断点,则会注册并正常进行。
我已经尝试了两天能想到的一切,包括将函数设为静态(伴侣对象)以尝试防止该对象被破坏或造成某种后果,但是没有运气。有人有什么想法吗?
class MigrationUtil : AsyncTask<Void, Void, Boolean>() {
companion object {
fun doStuff() {
val context : Context = ApplicationName.applicationContext()
val storageManager : StorageManager = context.getSystemService(Context.STORAGE_SERVICE) as StorageManager
val path = "/storage/emulated/0/Android/obb/com.example.appname/example.filename.obb"
if(File(path).exists()) {
Log.i("MigrationUtil", "File exists")
->Breakpoint<- storageManager.mountObb(path, "gibberishfilekey", object : OnObbStateChangeListener() {
override fun onObbStateChange(path: String?, state: Int) {
->Breakpoint<- Log.i("MigrationUtil", "onObbStateChanged")
super.onObbStateChange(path, state)
}
})
} else {
Log.e("MigrationUtil", "File does not exist")
}
}
}
override fun doInBackground(vararg p0: Void?): Boolean {
doStuff()
return true
}
}