├── .google └── packaging.yaml ├── Application ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── example │ │ └── android │ │ └── customnotifications │ │ └── MainActivity.java │ └── res │ ├── drawable-hdpi-v11 │ └── ic_stat_custom.png │ ├── drawable-hdpi-v9 │ └── ic_stat_custom.png │ ├── drawable-hdpi │ ├── ic_launcher.png │ ├── ic_stat_custom.png │ └── tile.9.png │ ├── drawable-ldpi-v11 │ └── ic_stat_custom.png │ ├── drawable-ldpi-v9 │ └── ic_stat_custom.png │ ├── drawable-mdpi-v11 │ └── ic_stat_custom.png │ ├── drawable-mdpi-v9 │ └── ic_stat_custom.png │ ├── drawable-mdpi │ ├── ic_launcher.png │ └── ic_stat_custom.png │ ├── drawable-xhdpi-v11 │ └── ic_stat_custom.png │ ├── drawable-xhdpi-v9 │ └── ic_stat_custom.png │ ├── drawable-xhdpi │ ├── ic_launcher.png │ ├── ic_stat_custom.png │ ├── robot.png │ └── robot_expanded.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── layout │ ├── notification.xml │ ├── notification_expanded.xml │ └── sample_main.xml │ ├── values-sw600dp │ ├── template-dimens.xml │ └── template-styles.xml │ ├── values-sw720dp-land │ └── dimens.xml │ ├── values-v11 │ └── template-styles.xml │ ├── values-v21 │ ├── base-colors.xml │ └── base-template-styles.xml │ ├── values-v9 │ └── styles.xml │ └── values │ ├── base-strings.xml │ ├── dimens.xml │ ├── strings.xml │ ├── styles.xml │ ├── template-dimens.xml │ └── template-styles.xml ├── CONTRIB.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── packaging.yaml ├── screenshots ├── icon-web.png ├── main-notification.png └── notification.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, UI] 10 | languages: [Java] 11 | solutions: [Mobile] 12 | github: android-CustomNotifications 13 | level: BEGINNER 14 | icon: screenshots/icon-web.png 15 | apiRefs: 16 | - android:android.app.Notification 17 | - android:android.app.NotificationManager 18 | - android:android.app.PendingIntent 19 | - android:android.support.v4.app.NotificationCompat 20 | - android:android.widget.RemoteViews 21 | license: apache2 22 | -------------------------------------------------------------------------------- /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:support-v13: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 16 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 | 19 | 20 | 24 | 25 | 26 | 27 | 32 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Application/src/main/java/com/example/android/customnotifications/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.android.customnotifications; 17 | 18 | import android.app.Activity; 19 | import android.app.Notification; 20 | import android.app.NotificationManager; 21 | import android.app.PendingIntent; 22 | import android.content.Intent; 23 | import android.os.Build; 24 | import android.os.Bundle; 25 | import android.support.v4.app.NotificationCompat; 26 | import android.view.View; 27 | import android.widget.RemoteViews; 28 | 29 | import java.text.DateFormat; 30 | import java.util.Date; 31 | 32 | public class MainActivity extends Activity { 33 | /** 34 | * This sample demonstrates notifications with custom content views. 35 | * 36 | *

On API level 16 and above a big content view is also defined that is used for the 37 | * 'expanded' notification. The notification is created by the NotificationCompat.Builder. 38 | * The expanded content view is set directly on the {@link android.app.Notification} once it has been build. 39 | * (See {@link android.app.Notification#bigContentView}.)

40 | * 41 | *

The content views are inflated as {@link android.widget.RemoteViews} directly from their XML layout 42 | * definitions using {@link android.widget.RemoteViews#RemoteViews(String, int)}.

43 | */ 44 | private void createNotification() { 45 | // BEGIN_INCLUDE(notificationCompat) 46 | NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 47 | // END_INCLUDE(notificationCompat) 48 | 49 | // BEGIN_INCLUDE(intent) 50 | //Create Intent to launch this Activity again if the notification is clicked. 51 | Intent i = new Intent(this, MainActivity.class); 52 | i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 53 | PendingIntent intent = PendingIntent.getActivity(this, 0, i, 54 | PendingIntent.FLAG_UPDATE_CURRENT); 55 | builder.setContentIntent(intent); 56 | // END_INCLUDE(intent) 57 | 58 | // BEGIN_INCLUDE(ticker) 59 | // Sets the ticker text 60 | builder.setTicker(getResources().getString(R.string.custom_notification)); 61 | 62 | // Sets the small icon for the ticker 63 | builder.setSmallIcon(R.drawable.ic_stat_custom); 64 | // END_INCLUDE(ticker) 65 | 66 | // BEGIN_INCLUDE(buildNotification) 67 | // Cancel the notification when clicked 68 | builder.setAutoCancel(true); 69 | 70 | // Build the notification 71 | Notification notification = builder.build(); 72 | // END_INCLUDE(buildNotification) 73 | 74 | // BEGIN_INCLUDE(customLayout) 75 | // Inflate the notification layout as RemoteViews 76 | RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification); 77 | 78 | // Set text on a TextView in the RemoteViews programmatically. 79 | final String time = DateFormat.getTimeInstance().format(new Date()).toString(); 80 | final String text = getResources().getString(R.string.collapsed, time); 81 | contentView.setTextViewText(R.id.textView, text); 82 | 83 | /* Workaround: Need to set the content view here directly on the notification. 84 | * NotificationCompatBuilder contains a bug that prevents this from working on platform 85 | * versions HoneyComb. 86 | * See https://code.google.com/p/android/issues/detail?id=30495 87 | */ 88 | notification.contentView = contentView; 89 | 90 | // Add a big content view to the notification if supported. 91 | // Support for expanded notifications was added in API level 16. 92 | // (The normal contentView is shown when the notification is collapsed, when expanded the 93 | // big content view set here is displayed.) 94 | if (Build.VERSION.SDK_INT >= 16) { 95 | // Inflate and set the layout for the expanded notification view 96 | RemoteViews expandedView = 97 | new RemoteViews(getPackageName(), R.layout.notification_expanded); 98 | notification.bigContentView = expandedView; 99 | } 100 | // END_INCLUDE(customLayout) 101 | 102 | // START_INCLUDE(notify) 103 | // Use the NotificationManager to show the notification 104 | NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 105 | nm.notify(0, notification); 106 | // END_INCLUDE(notify) 107 | } 108 | 109 | @Override 110 | protected void onCreate(Bundle savedInstanceState) { 111 | super.onCreate(savedInstanceState); 112 | setContentView(R.layout.sample_main); 113 | } 114 | 115 | /** 116 | * Create and show a notification with a custom layout. 117 | * This callback is defined through the 'onClick' attribute of the 118 | * 'Show Notification' button in the XML layout. 119 | * 120 | * @param v 121 | */ 122 | public void showNotificationClicked(View v) { 123 | createNotification(); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /Application/src/main/res/drawable-hdpi-v11/ic_stat_custom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-hdpi-v11/ic_stat_custom.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-hdpi-v9/ic_stat_custom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-hdpi-v9/ic_stat_custom.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-hdpi/ic_stat_custom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-hdpi/ic_stat_custom.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-hdpi/tile.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-hdpi/tile.9.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-ldpi-v11/ic_stat_custom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-ldpi-v11/ic_stat_custom.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-ldpi-v9/ic_stat_custom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-ldpi-v9/ic_stat_custom.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-mdpi-v11/ic_stat_custom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-mdpi-v11/ic_stat_custom.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-mdpi-v9/ic_stat_custom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-mdpi-v9/ic_stat_custom.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-mdpi/ic_stat_custom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-mdpi/ic_stat_custom.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-xhdpi-v11/ic_stat_custom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-xhdpi-v11/ic_stat_custom.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-xhdpi-v9/ic_stat_custom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-xhdpi-v9/ic_stat_custom.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-xhdpi/ic_stat_custom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-xhdpi/ic_stat_custom.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-xhdpi/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-xhdpi/robot.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-xhdpi/robot_expanded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-xhdpi/robot_expanded.png -------------------------------------------------------------------------------- /Application/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-CustomNotifications/2b80604e69b4747cdf8b0d0dfff65cdb7f9b5336/Application/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Application/src/main/res/layout/notification.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 17 | 18 | 19 | 20 | 25 | 26 | 32 | 33 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Application/src/main/res/layout/notification_expanded.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 30 | 31 | 42 | 43 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Application/src/main/res/layout/sample_main.xml: -------------------------------------------------------------------------------- 1 | 15 | 16 | 18 | 19 | 30 | 31 | 35 | 36 |