user23561978
user23561978

Reputation: 1

How to start an activity by tapping on a WearOS watch face?

I want to create a WearOS watch face that starts an activity when tapped anywhere. I tried to achieve this using Watch Face Format, but I'm open for other solutions.

I used Simple Analog example as base for my watch face and added a Launch tag. This works well when I use a constant like ALARM as target:

<Launch target="ALARM"></Launch>

(A view to create a new alarm opens on tap.)

But when I use an activity instead, the app crashes when I tap the watch face:

<Launch target=".MainActivity"></Launch>

There is no error message, when the app crashes, but earlierr, when I install the app in the emulator (green play button in Android studio), I get this message:

[ProviderGetter]Fetched empty list of supported providers: supportedTypes = null, packageName = com.example.simpleanalog, watchFaceId = null

My watchface.xml looks like this:

<WatchFace width="450" height="450">
    <Metadata key="CLOCK_TYPE" value="ANALOG"/>
    <Metadata key="PREVIEW_TIME" value="10:08:32"/>
    <Scene backgroundColor="#ff000000">
        <Group x="0" y="0" width="450" height="450">
            <Launch target=".MainActivity">
            </Launch>
            <AnalogClock x="0" y="0" width="450" height="450">
                <SecondHand resource="@drawable/second_hand" x="224" y="10"
                    width="2" height="215" pivotX="0.5" pivotY="1">
                    <Variant mode="AMBIENT" target="alpha" value="0"/>
                    <Sweep frequency="15"/>
                </SecondHand>
                <MinuteHand resource="@drawable/minute_hand" x="220" y="75"
                    width="10" height="150" pivotX="0.5" pivotY="1">
                    <Variant mode="AMBIENT" target="alpha" value="0"/>
                </MinuteHand>
                <HourHand resource="@drawable/hour_hand" x="220" y="125"
                    width="10" height="100" pivotX="0.5" pivotY="1">
                    <Variant mode="AMBIENT" target="alpha" value="0"/>
                </HourHand>
            </AnalogClock>
        </Group>
    </Scene>
</WatchFace>

The MainActivity is very simple:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

I added it to the manifest like this:

<activity
    android:name=".MainActivity"
    android:exported="true" />

Upvotes: 0

Views: 114

Answers (0)

Related Questions