0

I have this project https://github.com/neuberfran/SmartDrive5 The issue is: the application (according to logcat) never passes in: Log.i(TAG, "Volto 101.00 ${teste}") in ModoAutomatico.kt File and in Log.i(ContentValues.TAG, "Volto 106.00") In DriverService.kt file

When I put application android:name="com.you.yourapp.ApplicationEx" in Manifest.xml I have new issue: ***Service Intent must be explicit: Intent { }***

enter image description here

How can I implement bindservice in this android things applications?

Boe-Dev
  • 1,585
  • 2
  • 14
  • 26
neuberfran
  • 359
  • 3
  • 18

1 Answers1

1

Android Things doesn't have any special requirements when it comes to binding services.

I have this project https://github.com/neuberfran/SmartDrive5

The code that you are using to bind to the service in your GitHub project is incorrect. The ComponentName constructor requires the package name of your app (not the package of the class), so your should look like this:

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)

Note this format is really only necessary if you are calling a service in a remote process. Since you are binding to a service from within the same app context, it's much more straightforward to construct the intent this way:

val serviceIntent = Intent(this, DriverService::class.java)
// Bind to the driver service
bindService(serviceIntent, callback, BIND_AUTO_CREATE)
devunwired
  • 62,780
  • 12
  • 127
  • 139
  • Tks. But not solved because he heart of the issue stay in manifest.xml. I think. How to I can put application ModoAutomatico class in manifest.xml? https://github.com/neuberfran/SmartDrive5/blob/master/app/src/main/AndroidManifest.xml. I'm currently calling this Class on the MainActivity.https://drive.google.com/file/d/1XqmHCtCwXniZf4ytwgJtMlZpL83t94FD/view?usp=sharing. What do you think about onCreate in DriverService.kt? – neuberfran Mar 18 '19 at 05:34
  • You don't instantiate a custom Application class manually. The system creates your Application and calls onCreate() automatically (before any activity is created). You should not be instantiating that class in your MainActivity. – devunwired Mar 18 '19 at 17:18
  • Not solved. When I commented the lines in MainActivity, the ModoAutomatico class (pics in drive url) it never been used and my issue in this topic will never be solved. What about AndroidManifest.xml ?https://drive.google.com/drive/folders/1zM9wMj6gaUwC8HXfUO-nPgT53Affh4Ak?usp=sharing – neuberfran Mar 18 '19 at 18:41
  • 2
    Your application class should be referenced in the tag of your manifest as android:name=".controlamotores.modooffline.ModoAutomatico". This won't remove the "never used" warning from Studio, but the class will be instantiated automatically when the app launches. In your original screenshot, you had this correct in your manifest. – devunwired Mar 20 '19 at 02:57
  • https://stackoverflow.com/questions/55410809/android-things-with-bindservice-and-kotlin-onresume-and-onpause-or-coroutines – neuberfran Mar 29 '19 at 14:58