Cannot import com.google.android.wearable.intent.RemoteIntent for Wear OS app

Viewed 409

I'm trying to implement an 'Open on phone' button on a Wear OS app, but am unable to import the RemoteIntent class.

When I add import com.google.android.wearable.intent.RemoteIntent to my MainActivity.java the wearable is underlined in red with a 'Cannot resolve symbol' error.

Do I need to add a particular dependency to my project for this to be available?

The docs for RemoteIntent don't give me any clues as to what I might be missing.

For context, I am trying to use the following snippet in my app:

private void openOnPhone(Uri uri) {
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    RemoteIntent.startRemoteActivity(this, intent, null);
    // 'Open on phone' confirmation overlay
    new ConfirmationOverlay().setType(ConfirmationOverlay.OPEN_ON_PHONE_ANIMATION).setMessage("Opened on phone").showOn(this);
}
3 Answers

You need to import:

androidx.wear:wear-remote-interactions:1.0.0

Then instead use something like:

RemoteActivityHelper(application).startRemoteActivity(
            Intent(Intent.ACTION_VIEW).apply {
                addCategory(Intent.CATEGORY_DEFAULT)
               .addCategory(Intent.CATEGORY_BROWSABLE)
                data = Uri.parse("some://uri")
            },
            null
        )

However, this library does require compileSdkVersion 31 (Android 12)

I think you need to add one or both of the following dependencies:

androidx.wear:wear-phone-interactions:1.0.0-beta01
androidx.wear:wear-remote-interactions:1.0.0-beta01

It's mentioned in the release notes here. There's also a note about renaming it that might be relevant to you:

We have added the RemoteIntentHelper class (previously RemoteIntent in the Wearable Support Library) which can be used for opening intents on other devices (i.e. from watch to phone). (I1d7e0)

This package:

implementation 'com.google.android.support:wearable:2.8.1'
Related