• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

Application/22-Nov-2023-359160

buildSrc/22-Nov-2023-1613

gradle/wrapper/22-Nov-2023-65

screenshots/22-Nov-2023-

CONTRIB.mdD22-Nov-20231.6 KiB3627

LICENSED22-Nov-202311.1 KiB204170

README.mdD22-Nov-20234 KiB10276

build.gradleD22-Nov-2023251 129

gradlewD22-Nov-20235.2 KiB173128

gradlew.batD22-Nov-20232.2 KiB8561

packaging.yamlD22-Nov-2023492 1610

settings.gradleD22-Nov-202322 21

template-params.xmlD22-Nov-20234.1 KiB10576

README.md

1
2Android BasicNotifications Sample
3===================================
4
5A basic app showing how to display events in the system's notification bar using
6the NotificationCompat API.
7NotificationCompat API is used for compatibility with older devices, running Android
81.6 (Donut) (API level 4) or newer.
9
10Introduction
11------------
12
13The [Notification API][1] allows the app developers to display a message outside
14of your application's normal UI.
15
16The class [Notification][2] was added in the Android 3.0 (API level 11), but this
17sample refers to the [NotificationCompat][3] class (part of the [support library][4]),
18 which offers the same functionality for Android 1.6 (API level 4) or newer.
19
20A Notificaiton can be created using Notification.Builder object.
21At bare minimum, a Builder object must include the following:
22- A small icon, set by [setSmallIcon()][5]
23- A title, set by [setContentTitle()][6]
24- Detail text, set by [setContentText()][7]
25
26in the code snippet, it looks like following.
27```java
28NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
29builder.setSmallIcon(R.drawable.ic_stat_notification);
30builder.setContentTitle("BasicNotifications Sample");
31builder.setContentText("Time to learn about notifications!");
32```
33
34To issue the notification, call notify() method in the [NotificationManager][8].
35The code snippet will immediately display the notification icon in the
36notification bar.
37
38```java
39NotificationManager notificationManager = (NotificationManager) getSystemService(
40        NOTIFICATION_SERVICE);
41notificationManager.notify(NOTIFICATION_ID, builder.build());
42```
43
44[1]: http://developer.android.com/guide/topics/ui/notifiers/notifications.html
45[2]: http://developer.android.com/reference/android/app/Notification.html
46[3]: http://developer.android.com/reference/android/support/v4/app/NotificationCompat.html
47[4]: http://developer.android.com/tools/support-library/index.html
48[5]: http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setSmallIcon(int)
49[6]: http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setContentTitle(java.lang.CharSequence)
50[7]: http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setContentText(java.lang.CharSequence)
51[8]: http://developer.android.com/reference/android/app/NotificationManager.html
52
53Pre-requisites
54--------------
55
56- Android SDK 28
57- Android Build Tools v28.0.3
58- Android Support Repository
59
60Screenshots
61-------------
62
63<img src="screenshots/main.png" height="400" alt="Screenshot"/>
64
65Getting Started
66---------------
67
68This sample uses the Gradle build system. To build this project, use the
69"gradlew build" command or use "Import Project" in Android Studio.
70
71Support
72-------
73
74- Google+ Community: https://plus.google.com/communities/105153134372062985968
75- Stack Overflow: http://stackoverflow.com/questions/tagged/android
76
77If you've found an error in this sample, please file an issue:
78https://github.com/googlesamples/android-BasicNotifications
79
80Patches are encouraged, and may be submitted by forking this project and
81submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
82
83License
84-------
85
86Copyright 2019 The Android Open Source Project, Inc.
87
88Licensed to the Apache Software Foundation (ASF) under one or more contributor
89license agreements.  See the NOTICE file distributed with this work for
90additional information regarding copyright ownership.  The ASF licenses this
91file to you under the Apache License, Version 2.0 (the "License"); you may not
92use this file except in compliance with the License.  You may obtain a copy of
93the License at
94
95http://www.apache.org/licenses/LICENSE-2.0
96
97Unless required by applicable law or agreed to in writing, software
98distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
99WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
100License for the specific language governing permissions and limitations under
101the License.
102