Skip to content

Commit fe5ebab

Browse files
committed
Wear Notifications snippets
1 parent aea6b59 commit fe5ebab

29 files changed

+741
-0
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/compose/ @android/devrel-compose
33
/car/ @android/devrel-car
44
/wear/ @android/devrel-wear
5+
/wearcompanion/ @android/devrel-wear
56
/xr/ @android/devrel-xr

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ wearInput = "1.2.0"
9595
wearOngoing = "1.1.0"
9696
wearToolingPreview = "1.0.0"
9797
webkit = "1.14.0"
98+
wearPhoneInteractions = "1.1.0"
9899

99100
[libraries]
100101
accompanist-adaptive = "com.google.accompanist:accompanist-adaptive:0.37.3"
@@ -235,6 +236,7 @@ roborazzi-rule = { module = "io.github.takahirom.roborazzi:roborazzi-junit-rule"
235236
validator-push = { module = "com.google.android.wearable.watchface.validator:validator-push", version.ref = "validatorPush" }
236237
wear-compose-material = { module = "androidx.wear.compose:compose-material", version.ref = "wearComposeMaterial" }
237238
wear-compose-material3 = { module = "androidx.wear.compose:compose-material3", version.ref = "wearComposeMaterial3" }
239+
androidx-wear-phone-interactions = { group = "androidx.wear", name = "wear-phone-interactions", version.ref = "wearPhoneInteractions" }
238240

239241
[plugins]
240242
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ include(
3535
":compose:snippets",
3636
":datastore",
3737
":wear",
38+
":wearcompanion",
3839
":views",
3940
":misc",
4041
":identity:credentialmanager",

wearcompanion/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

wearcompanion/build.gradle.kts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
plugins {
2+
alias(libs.plugins.android.application)
3+
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.compose.compiler)
5+
}
6+
7+
android {
8+
namespace = "com.example.wear.snippets"
9+
compileSdk = 36
10+
11+
defaultConfig {
12+
applicationId = "com.example.wear.snippets"
13+
minSdk = 28
14+
targetSdk = 36
15+
versionCode = 1
16+
versionName = "1.0"
17+
18+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
19+
}
20+
21+
buildTypes {
22+
release {
23+
isMinifyEnabled = false
24+
proguardFiles(
25+
getDefaultProguardFile("proguard-android-optimize.txt"),
26+
"proguard-rules.pro"
27+
)
28+
}
29+
}
30+
compileOptions {
31+
sourceCompatibility = JavaVersion.VERSION_21
32+
targetCompatibility = JavaVersion.VERSION_21
33+
}
34+
kotlin {
35+
jvmToolchain(21)
36+
}
37+
buildFeatures {
38+
compose = true
39+
}
40+
}
41+
42+
dependencies {
43+
implementation(libs.androidx.core.ktx)
44+
implementation(libs.androidx.lifecycle.runtime)
45+
implementation(libs.androidx.activity.compose)
46+
implementation(platform(libs.androidx.compose.bom))
47+
implementation(libs.androidx.compose.ui)
48+
implementation(libs.androidx.compose.ui.graphics)
49+
implementation(libs.androidx.compose.ui.tooling.preview)
50+
implementation(libs.androidx.compose.material3)
51+
implementation(libs.androidx.wear.phone.interactions)
52+
testImplementation(libs.junit)
53+
androidTestImplementation(libs.androidx.test.ext.junit)
54+
androidTestImplementation(libs.androidx.test.espresso.core)
55+
androidTestImplementation(platform(libs.androidx.compose.bom))
56+
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
57+
debugImplementation(libs.androidx.compose.ui.tooling)
58+
debugImplementation(libs.androidx.compose.ui.test.manifest)
59+
}

wearcompanion/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
18+
19+
<application
20+
android:allowBackup="true"
21+
android:icon="@mipmap/ic_launcher"
22+
android:label="@string/app_name"
23+
android:roundIcon="@mipmap/ic_launcher_round"
24+
android:supportsRtl="true"
25+
android:theme="@style/Theme.Snippets">
26+
<activity
27+
android:name=".MainActivity"
28+
android:exported="true"
29+
android:label="@string/app_name"
30+
android:theme="@style/Theme.Snippets">
31+
<intent-filter>
32+
<action android:name="android.intent.action.MAIN" />
33+
34+
<category android:name="android.intent.category.LAUNCHER" />
35+
</intent-filter>
36+
</activity>
37+
38+
<!-- [START android_wearcompanion_notification_bridge_manifest] -->
39+
<!-- Beware, this can have unintended consequences before the user is signed-in -->
40+
<meta-data
41+
android:name="com.google.android.wearable.notificationBridgeMode"
42+
android:value="NO_BRIDGING" />
43+
<!-- [END android_wearcompanion_notification_bridge_manifest] -->
44+
</application>
45+
46+
</manifest>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.wear.snippets
18+
19+
import android.os.Bundle
20+
import androidx.activity.ComponentActivity
21+
import androidx.activity.compose.setContent
22+
import androidx.activity.enableEdgeToEdge
23+
import androidx.compose.foundation.layout.fillMaxSize
24+
import androidx.compose.foundation.layout.padding
25+
import androidx.compose.material3.Scaffold
26+
import androidx.compose.material3.Text
27+
import androidx.compose.runtime.Composable
28+
import androidx.compose.ui.Modifier
29+
import androidx.compose.ui.tooling.preview.Preview
30+
import com.example.wear.snippets.ui.theme.SnippetsTheme
31+
32+
class MainActivity : ComponentActivity() {
33+
override fun onCreate(savedInstanceState: Bundle?) {
34+
super.onCreate(savedInstanceState)
35+
enableEdgeToEdge()
36+
setContent {
37+
SnippetsTheme {
38+
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
39+
Greeting(
40+
name = "Android",
41+
modifier = Modifier.padding(innerPadding)
42+
)
43+
}
44+
}
45+
}
46+
}
47+
}
48+
49+
@Composable
50+
fun Greeting(name: String, modifier: Modifier = Modifier) {
51+
Text(
52+
text = "Hello $name!",
53+
modifier = modifier
54+
)
55+
}
56+
57+
@Preview(showBackground = true)
58+
@Composable
59+
fun GreetingPreview() {
60+
SnippetsTheme {
61+
Greeting("Android")
62+
}
63+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.wear.snippets.notifications
18+
19+
import android.content.Context
20+
import androidx.core.app.NotificationCompat
21+
import androidx.wear.phone.interactions.notifications.BridgingConfig
22+
import androidx.wear.phone.interactions.notifications.BridgingManager
23+
24+
private const val channelId = "1"
25+
26+
fun setBridgeTags(context: Context) {
27+
// [START android_wearcompanion_notification_bridge_tags]
28+
val notification = NotificationCompat.Builder(context, channelId)
29+
// ... set other fields ...
30+
.extend(
31+
NotificationCompat.WearableExtender()
32+
.setBridgeTag("tagOne")
33+
)
34+
.build()
35+
// [END android_wearcompanion_notification_bridge_tags]
36+
}
37+
38+
fun disableBridging(context: Context) {
39+
// [START android_wearcompanion_notification_disable_bridging]
40+
// In this example, bridging is only enabled for tagOne, tagTwo and tagThree.
41+
BridgingManager.fromContext(context).setConfig(
42+
BridgingConfig.Builder(context, isBridgingEnabled = false)
43+
.addExcludedTags(listOf("tagOne", "tagTwo", "tagThree"))
44+
.build()
45+
)
46+
// [END android_wearcompanion_notification_disable_bridging]
47+
}
48+
49+
fun setDismissalId(context: Context) {
50+
// [START android_wearcompanion_notification_dismissal_id]
51+
val notification = NotificationCompat.Builder(context, channelId)
52+
// ... set other fields ...
53+
.extend(
54+
NotificationCompat.WearableExtender()
55+
.setDismissalId("abc123")
56+
)
57+
.build()
58+
// [END android_wearcompanion_notification_dismissal_id]
59+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.wear.snippets.ui.theme
18+
19+
import androidx.compose.ui.graphics.Color
20+
21+
val Purple80 = Color(0xFFD0BCFF)
22+
val PurpleGrey80 = Color(0xFFCCC2DC)
23+
val Pink80 = Color(0xFFEFB8C8)
24+
25+
val Purple40 = Color(0xFF6650a4)
26+
val PurpleGrey40 = Color(0xFF625b71)
27+
val Pink40 = Color(0xFF7D5260)

0 commit comments

Comments
 (0)