我有这个项目https://github.com/neuberfran/SmartDrive5 问题是:应用程序(根据logcat)永远不会传入: ModoAutomatico.kt 中的Log.i(TAG,“ Volto 101.00 $ {teste}”) 文件和Log.i(ContentValues.TAG,“ Volto 106.00”) 在 DriverService.kt 文件
中当我放
应用
android:name="com.you.yourapp.ApplicationEx"
中的Manifest.xml
我有新问题:***Service Intent must be explicit: Intent { }***
如何在此android Things应用程序中实现bindservice?
答案 0 :(得分:1)
Android Things在绑定服务方面没有任何特殊要求。
用于绑定到GitHub项目中的服务的代码不正确。 ComponentName
构造函数需要您应用的程序包名称(而不是类的程序包),因此您应如下所示:
val driverService = ComponentName(
"com.example.neube.smartdrive",
"com.example.neube.smartdrive.controlamotores.modooffline.DriverService"
)
val serviceIntent = Intent()
serviceIntent.component = driverService
// Bind to the driver service
bindService(serviceIntent, callback, BIND_AUTO_CREATE)
请注意,仅当您在远程进程中调用服务时,才真正需要这种格式。由于您是从同一应用程序上下文中绑定到服务,因此以这种方式构造意图要简单得多:
val serviceIntent = Intent(this, DriverService::class.java)
// Bind to the driver service
bindService(serviceIntent, callback, BIND_AUTO_CREATE)