Skip to content

Commit f564001

Browse files
committed
feat(views): Add basic notification snippet
Add a basic notification snippet and associated files to the views module. Region-Tag: android_views_notifications_build_basic
1 parent 27c462c commit f564001

File tree

8 files changed

+69
-7
lines changed

8 files changed

+69
-7
lines changed

views/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ plugins {
1818
}
1919

2020
android {
21-
namespace = "com.example.example.snippet.views"
21+
namespace = "com.example.android.views"
2222
compileSdk = 35
2323

2424
defaultConfig {
@@ -48,6 +48,8 @@ android {
4848

4949
dependencies {
5050

51+
implementation("androidx.core:core:1.13.1")
52+
implementation("androidx.appcompat:appcompat:1.6.1")
5153
implementation(libs.androidx.core.ktx)
5254
implementation(libs.androidx.appcompat)
5355
implementation(libs.google.android.material)

views/src/main/AndroidManifest.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,13 @@
1515
limitations under the License.
1616
-->
1717
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
18-
18+
<application>
19+
<activity android:name=".notifications.NotificationSnippets$MainActivity"
20+
android:exported="true">
21+
<intent-filter>
22+
<action android:name="android.intent.action.MAIN" />
23+
<category android:name="android.intent.category.LAUNCHER" />
24+
</intent-filter>
25+
</activity>
26+
</application>
1927
</manifest>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.android.views.notifications;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import androidx.core.app.NotificationCompat;
6+
import com.example.android.views.R;
7+
8+
public class NotificationSnippets {
9+
private static final String CHANNEL_ID = "channel_id";
10+
private static final String textTitle = "Notification Title";
11+
private static final String textContent = "Notification Content";
12+
13+
public static class MainActivity extends Activity {
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
// [START android_views_notifications_build_basic]
18+
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
19+
.setSmallIcon(R.drawable.notification_icon)
20+
.setContentTitle(textTitle)
21+
.setContentText(textContent)
22+
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
23+
// [END android_views_notifications_build_basic]
24+
}
25+
}
26+
}

views/src/main/java/com/example/example/snippet/views/appwidget/AppWidgetSnippets.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import android.widget.RemoteViews
2525
import androidx.glance.GlanceId
2626
import androidx.glance.appwidget.GlanceAppWidget
2727
import androidx.glance.appwidget.compose
28-
import com.example.example.snippet.views.R
28+
import com.example.android.views.R
2929

3030
class ExampleAppWidget : GlanceAppWidget() {
3131
override suspend fun provideGlance(context: Context, id: GlanceId) {

views/src/main/java/insets/SystemBarProtectionSnippet.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import androidx.core.view.ViewCompat
2525
import androidx.core.view.WindowInsetsCompat
2626
import androidx.core.view.insets.GradientProtection
2727
import androidx.core.view.insets.ProtectionLayout
28-
import com.example.example.snippet.views.R
28+
import com.example.android.views.R
2929

3030
class SystemBarProtectionSnippet : AppCompatActivity() {
3131

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:shape="rectangle">
19+
<solid android:color="#FF0000" />
20+
<size android:width="24dp"
21+
android:height="24dp" />
22+
</shape>

watchfacepush/validator/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ plugins {
2222
application
2323
}
2424

25+
kotlin {
26+
jvmToolchain(17)
27+
}
28+
2529
application {
2630
mainClass.set("com.example.validator.Main")
2731
}

xr/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ android {
1616
versionName = "1.0"
1717
}
1818
compileOptions {
19-
sourceCompatibility = JavaVersion.VERSION_11
20-
targetCompatibility = JavaVersion.VERSION_11
19+
sourceCompatibility = JavaVersion.VERSION_17
20+
targetCompatibility = JavaVersion.VERSION_17
2121
}
2222
kotlin {
23-
jvmToolchain(11)
23+
jvmToolchain(17)
2424
}
2525
buildFeatures {
2626
compose = true

0 commit comments

Comments
 (0)