I am trying to the use facilities of the ComplicationManager in AndroidX, and to do so the Gemini AI engine tells me I need to include the following implementation directive in the dependencies block of the app level Build.gradle file:
dependencies { implementation "androidx.wear.watchface:watchface-complications:1.2.1" // Or the latest stable version // ... other dependencies }
Doing this results in the following error:
e: file:///C:/Users/poust/AndroidStudioProjects/SmartTimer2/app/src/main/java/com/example/smarttimer2/AppLauncherComplicationProviderService.kt:9:47 Unresolved reference: ComplicationManager Line 9 of the applicable code is:
import android.support.wearable.complications.ComplicationManager To ensure that the build.gradle file includes the Maven repository, I verified the Maven repository is called in the Buildscript block of the Build.gradle file as shown below. The Maven repo holds the watchface-complications:1.2.1 code - see the following link: https://mvnrepository.com/artifact/androidx.wear.watchface/watchface-complications-data-source/1.2.1
buildscript { repositories { google() mavenCentral() } }
The objective of what I am trying to do is to execute the following code to start an app on a complication tap (copied from Gemini)
class AppLauncherComplicationProviderService : ComplicationProviderService() { override fun onComplicationActivated( complicationId: Int, type: Int, watchFaceComponent: ComponentName ) { Log.d(TAG, "onComplicationActivated(): $complicationId, type: $type, component: $watchFaceComponent") // Optional: Perform any setup needed when the complication becomes active } override fun onComplicationDeactivated(complicationId: Int) { Log.d(TAG, "onComplicationDeactivated(): $complicationId") // Optional: Perform any cleanup needed when the complication becomes inactive } override fun onComplicationUpdate( complicationId: Int, dataType: Int, complicationManager: ComplicationManager ) { Log.d(TAG, "onComplicationUpdate(): $complicationId, type: $dataType") if (dataType == ComplicationData.TYPE_LAUNCH_APP) { // Specify the component (package name and activity class) of the app to launch val launchIntent = Intent(Intent.ACTION_MAIN) .addCategory(Intent.CATEGORY_LAUNCHER) .setComponent(ComponentName( "com.example.my_target_app", // Replace with the target app's package name "com.example.my_target_app.MainActivity" // Replace with the target app's main activity )) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) // Create a PendingIntent to wrap the launch Intent val tapAction = PendingIntent.getActivity( this, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE ) // Create the ComplicationData for launching the app val complicationData = ComplicationData.Builder(ComplicationData.TYPE_LAUNCH_APP) .setIcon( Icon.createWithResource( this, R.drawable.ic_app_launcher // Replace with your app's launcher icon resource ) ) .setShortTitle(getString(R.string.app_name_launcher)) // Optional: Short title .setTapAction(tapAction) .build() // Update the complication on the watch face complicationManager.updateComplicationData(complicationId, complicationData) } else { complicationManager.noUpdateRequired(complicationId) } } }
Any insight that you could provide me on how to either resolve this compile problem or an alternate means of starting an app on a tap complication tap, I would be grateful.