android事务中的bindservice manifest.xml选项ACTION_BOOT_COMPLETED

问题描述 投票:0回答:1

我有这个项目https://github.com/neuberfran/SmartDrive5问题是:应用程序(根据logcat)从未传入:Logo中的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 { }***

enter image description here

如何在这个android东西应用程序中实现bindservice?

android kotlin iot android-things
1个回答
1
投票

Android Things在绑定服务方面没有任何特殊要求。

我有这个项目https://github.com/neuberfran/SmartDrive5

您用于绑定到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)

请注意,只有在远程进程中调用服务时才需要使用此格式。由于您从同一个应用程序上下文中绑定到服务,因此以这种方式构造intent更为直接:

val serviceIntent = Intent(this, DriverService::class.java)
// Bind to the driver service
bindService(serviceIntent, callback, BIND_AUTO_CREATE)
© www.soinside.com 2019 - 2024. All rights reserved.