├── .google └── packaging.yaml ├── Application ├── build.gradle ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── android │ │ │ └── basicnotifications │ │ │ └── MainActivity.java │ │ └── res │ │ ├── drawable-hdpi-v11 │ │ └── ic_stat_notification.png │ │ ├── drawable-hdpi-v9 │ │ └── ic_stat_notification.png │ │ ├── drawable-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_stat_notification.png │ │ └── tile.9.png │ │ ├── drawable-ldpi-v11 │ │ └── ic_stat_notification.png │ │ ├── drawable-ldpi-v9 │ │ └── ic_stat_notification.png │ │ ├── drawable-mdpi-v11 │ │ └── ic_stat_notification.png │ │ ├── drawable-mdpi-v9 │ │ └── ic_stat_notification.png │ │ ├── drawable-mdpi │ │ ├── ic_launcher.png │ │ └── ic_stat_notification.png │ │ ├── drawable-xhdpi-v11 │ │ └── ic_stat_notification.png │ │ ├── drawable-xhdpi-v9 │ │ └── ic_stat_notification.png │ │ ├── drawable-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_stat_notification.png │ │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ │ ├── layout │ │ └── sample_layout.xml │ │ ├── values-sw600dp │ │ ├── template-dimens.xml │ │ └── template-styles.xml │ │ ├── values-v11 │ │ └── template-styles.xml │ │ ├── values-v21 │ │ ├── base-colors.xml │ │ └── base-template-styles.xml │ │ └── values │ │ ├── base-strings.xml │ │ ├── strings.xml │ │ ├── template-dimens.xml │ │ └── template-styles.xml └── tests │ ├── AndroidManifest.xml │ └── src │ └── com │ └── example │ └── android │ └── basicnotifications │ └── tests │ └── SampleTests.java ├── CONTRIB.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── packaging.yaml ├── screenshots └── main.png └── settings.gradle /.google/packaging.yaml: -------------------------------------------------------------------------------- 1 | 2 | # GOOGLE SAMPLE PACKAGING DATA 3 | # 4 | # This file is used by Google as part of our samples packaging process. 5 | # End users may safely ignore this file. It has no relevance to other systems. 6 | --- 7 | status: PUBLISHED 8 | technologies: [Android] 9 | categories: [Notification] 10 | languages: [Java] 11 | solutions: [Mobile] 12 | github: android-BasicNotifications 13 | level: BEGINNER 14 | icon: Application/src/main/big_icon.png 15 | apiRefs: 16 | - android:android.app.NotificationManager 17 | - android:android.support.v4.app.NotificationCompat 18 | license: apache2 19 | -------------------------------------------------------------------------------- /Application/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | buildscript { 3 | repositories { 4 | jcenter() 5 | google() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.0.1' 10 | } 11 | } 12 | 13 | apply plugin: 'com.android.application' 14 | 15 | repositories { 16 | jcenter() 17 | google() 18 | } 19 | 20 | dependencies { 21 | compile "com.android.support:support-v4:27.0.2" 22 | compile "com.android.support:gridlayout-v7:27.0.2" 23 | compile "com.android.support:cardview-v7:27.0.2" 24 | compile "com.android.support:appcompat-v7:27.0.2" 25 | } 26 | 27 | // The sample build uses multiple directories to 28 | // keep boilerplate and common code separate from 29 | // the main sample code. 30 | List dirs = [ 31 | 'main', // main sample code; look here for the interesting stuff. 32 | 'common', // components that are reused by multiple samples 33 | 'template'] // boilerplate code that is generated by the sample template process 34 | 35 | android { 36 | compileSdkVersion 27 37 | 38 | buildToolsVersion "27.0.2" 39 | 40 | defaultConfig { 41 | minSdkVersion 8 42 | targetSdkVersion 27 43 | } 44 | 45 | compileOptions { 46 | sourceCompatibility JavaVersion.VERSION_1_7 47 | targetCompatibility JavaVersion.VERSION_1_7 48 | } 49 | 50 | sourceSets { 51 | main { 52 | dirs.each { dir -> 53 | java.srcDirs "src/${dir}/java" 54 | res.srcDirs "src/${dir}/res" 55 | } 56 | } 57 | androidTest.setRoot('tests') 58 | androidTest.java.srcDirs = ['tests/src'] 59 | 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Application/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | 24 | 25 | 30 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Application/src/main/java/com/example/android/basicnotifications/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.android.basicnotifications; 2 | 3 | import android.app.Activity; 4 | import android.app.NotificationManager; 5 | import android.app.PendingIntent; 6 | import android.content.Intent; 7 | import android.graphics.BitmapFactory; 8 | import android.net.Uri; 9 | import android.os.Bundle; 10 | import android.support.v4.app.NotificationCompat; 11 | import android.view.View; 12 | 13 | /** 14 | * The entry point to the BasicNotification sample. 15 | */ 16 | public class MainActivity extends Activity { 17 | /** 18 | * A numeric value that identifies the notification that we'll be sending. 19 | * This value needs to be unique within this app, but it doesn't need to be 20 | * unique system-wide. 21 | */ 22 | public static final int NOTIFICATION_ID = 1; 23 | 24 | public void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.sample_layout); 27 | 28 | } 29 | 30 | /** 31 | * Send a sample notification using the NotificationCompat API. 32 | */ 33 | public void sendNotification(View view) { 34 | 35 | // BEGIN_INCLUDE(build_action) 36 | /** Create an intent that will be fired when the user clicks the notification. 37 | * The intent needs to be packaged into a {@link android.app.PendingIntent} so that the 38 | * notification service can fire it on our behalf. 39 | */ 40 | Intent intent = new Intent(Intent.ACTION_VIEW, 41 | Uri.parse("http://developer.android.com/reference/android/app/Notification.html")); 42 | PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); 43 | // END_INCLUDE(build_action) 44 | 45 | // BEGIN_INCLUDE (build_notification) 46 | /** 47 | * Use NotificationCompat.Builder to set up our notification. 48 | */ 49 | NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 50 | 51 | /** Set the icon that will appear in the notification bar. This icon also appears 52 | * in the lower right hand corner of the notification itself. 53 | * 54 | * Important note: although you can use any drawable as the small icon, Android 55 | * design guidelines state that the icon should be simple and monochrome. Full-color 56 | * bitmaps or busy images don't render well on smaller screens and can end up 57 | * confusing the user. 58 | */ 59 | builder.setSmallIcon(R.drawable.ic_stat_notification); 60 | 61 | // Set the intent that will fire when the user taps the notification. 62 | builder.setContentIntent(pendingIntent); 63 | 64 | // Set the notification to auto-cancel. This means that the notification will disappear 65 | // after the user taps it, rather than remaining until it's explicitly dismissed. 66 | builder.setAutoCancel(true); 67 | 68 | /** 69 | *Build the notification's appearance. 70 | * Set the large icon, which appears on the left of the notification. In this 71 | * sample we'll set the large icon to be the same as our app icon. The app icon is a 72 | * reasonable default if you don't have anything more compelling to use as an icon. 73 | */ 74 | builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); 75 | 76 | /** 77 | * Set the text of the notification. This sample sets the three most commononly used 78 | * text areas: 79 | * 1. The content title, which appears in large type at the top of the notification 80 | * 2. The content text, which appears in smaller text below the title 81 | * 3. The subtext, which appears under the text on newer devices. Devices running 82 | * versions of Android prior to 4.2 will ignore this field, so don't use it for 83 | * anything vital! 84 | */ 85 | builder.setContentTitle("BasicNotifications Sample"); 86 | builder.setContentText("Time to learn about notifications!"); 87 | builder.setSubText("Tap to view documentation about notifications."); 88 | 89 | // END_INCLUDE (build_notification) 90 | 91 | // BEGIN_INCLUDE(send_notification) 92 | /** 93 | * Send the notification. This will immediately display the notification icon in the 94 | * notification bar. 95 | */ 96 | NotificationManager notificationManager = (NotificationManager) getSystemService( 97 | NOTIFICATION_SERVICE); 98 | notificationManager.notify(NOTIFICATION_ID, builder.build()); 99 | // END_INCLUDE(send_notification) 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Application/src/main/res/drawable-hdpi-v11/ic_stat_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-hdpi-v11/ic_stat_notification.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-hdpi-v9/ic_stat_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-hdpi-v9/ic_stat_notification.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-hdpi/ic_stat_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-hdpi/ic_stat_notification.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-hdpi/tile.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-hdpi/tile.9.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-ldpi-v11/ic_stat_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-ldpi-v11/ic_stat_notification.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-ldpi-v9/ic_stat_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-ldpi-v9/ic_stat_notification.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-mdpi-v11/ic_stat_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-mdpi-v11/ic_stat_notification.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-mdpi-v9/ic_stat_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-mdpi-v9/ic_stat_notification.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-mdpi/ic_stat_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-mdpi/ic_stat_notification.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-xhdpi-v11/ic_stat_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-xhdpi-v11/ic_stat_notification.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-xhdpi-v9/ic_stat_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-xhdpi-v9/ic_stat_notification.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-xhdpi/ic_stat_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-xhdpi/ic_stat_notification.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-BasicNotifications/9db4d1309a2da9520e6623639fc125bc3059844c/Application/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Application/src/main/res/layout/sample_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 24 | 25 | 33 | 34 |