# Android Notifications

**URL:** <https://discourse.processing.org/t/android-notifications/1914>\
**Category:** Processing for Android\
**Created:** [July 19, 2018, 4:06pm UTC](https://discourse.processing.org/t/android-notifications/1914 "2018-07-19T16:06:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [July 19, 2018, 4:06pm UTC](https://discourse.processing.org/t/android-notifications/1914/1 "2018-07-19T16:06:14Z")

</div>

EXAM LINK : [https://www.androidauthority.com/how-to-create-android-notifications-707254/](https://www.androidauthority.com/how-to-create-android-notifications-707254/)

 ![main](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/9555454d067b8e846df100ac0381b83eb8372983.jpg)

I want to display a notification as shown in the figure.

1. Is it possible to processing at android mode?

2. If possible, please give us some example source code. help me!

---

<div class="post-metadata">

**Author:** ![Andres](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/andres/32/18007_2.png) [@Andres](https://discourse.processing.org/u/Andres)\
**Post date:** [July 19, 2018, 5:50pm UTC](https://discourse.processing.org/t/android-notifications/1914/3 "2018-07-19T17:50:49Z")

</div>

It is possible, but the problem is that the message API requires the android.support.v4 libraries that are not included with the platform SDK. Anyways… if you have this code in the PDE:

```java
import android.os.Build;

import android.app.NotificationChannel;
import android.app.NotificationManager;

import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;

import static android.content.Context.NOTIFICATION_SERVICE;

String CHANNEL_ID = "processing_test.notifications";

void setup() {
  fullScreen();
  initNotifications();
}

void draw() {
  background(150);
}

void mousePressed() {
  showNotification();
}

void initNotifications() {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    // Create the NotificationChannel, but only on API 26+ because
    // the NotificationChannel class is new and not in the support library
    String name = "Test Notifications";
    String description = "Notifications from Processing sketch are shown in this channel";
    int importance = NotificationManager.IMPORTANCE_HIGH;
    NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
    channel.setDescription(description);
    // Register the channel with the system
    NotificationManager notificationManager = (NotificationManager)
      getContext().getSystemService(NOTIFICATION_SERVICE);
    notificationManager.createNotificationChannel(channel);
  }
}

void showNotification() {
  // Create an explicit intent for an Activity in your app
  NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getContext(), CHANNEL_ID)
    .setSmallIcon(R.drawable.icon)
    .setContentTitle("This is a messsage")
    .setContentText("Mouse pressed event detected!")
    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
    .setPriority(NotificationCompat.PRIORITY_HIGH)
    .setAutoCancel(true);

  // Show the notification
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getContext());
  // notificationId is a unique int for each notification that you must define
  int notificationId = 666;
  notificationManager.notify(notificationId, mBuilder.build());
}

```

it will give you a bunch of errors in the PDE (“The import android.support.v4 cannot be resolved” etc.) but you should still be able to run it because these dependencies will be resolved when the sketch is compiled, and get the notification:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/114d73caba8b38794bb8cdf2e8fdd59f626652bf.jpg)

I hope this is useful. Maybe the android mode should include the support libraries so there are no errors in the PDE when importing them…

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [July 19, 2018, 8:52pm UTC](https://discourse.processing.org/t/android-notifications/1914/4 "2018-07-19T20:52:09Z")

</div>

@Andres

Thank you for your kind reply.

The following error occurred.

Why is this happening?

* * *

1. WARNING in C:\Users\SJGWAK\AppData\Local\Temp\android6928576046861478137sketch\src\processing\test\notifications\MainActivity.java (at line 11)  
import android.support.v4.content.ContextCompat;  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
The import android.support.v4.content.ContextCompat is never used

* * *

1. WARNING in C:\Users\SJGWAK\AppData\Local\Temp\android6928576046861478137sketch\src\processing\test\notifications\MainActivity.java (at line 15)  
import android.Manifest;  
^^^^^^^^^^^^^^^^  
The import android.Manifest is never used

* * *

1. WARNING in C:\Users\SJGWAK\AppData\Local\Temp\android6928576046861478137sketch\src\processing\test\notifications\MainActivity.java (at line 49)  
int check;  
^^^^^  
The value of the local variable check is not used

* * *

* * *

1. ERROR in C:\Users\SJGWAK\AppData\Local\Temp\android6928576046861478137sketch\src\processing\test\notifications\Notifications.java (at line 9)  
import android.app.NotificationChannel;  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
The import android.app.NotificationChannel cannot be resolved

* * *

1. ERROR in C:\Users\SJGWAK\AppData\Local\Temp\android6928576046861478137sketch\src\processing\test\notifications\Notifications.java (at line 52)  
if (Build.VERSION.SDK\_INT \>= Build.VERSION\_CODES.O) {  
^  
O cannot be resolved or is not a field

* * *

1. ERROR in C:\Users\SJGWAK\AppData\Local\Temp\android6928576046861478137sketch\src\processing\test\notifications\Notifications.java (at line 57)  
int importance = NotificationManager.IMPORTANCE\_HIGH;  
^^^^^^^^^^^^^^^  
IMPORTANCE\_HIGH cannot be resolved or is not a field

* * *

1. ERROR in C:\Users\SJGWAK\AppData\Local\Temp\android6928576046861478137sketch\src\processing\test\notifications\Notifications.java (at line 58)  
NotificationChannel channel = new NotificationChannel(CHANNEL\_ID, name, importance);  
^^^^^^^^^^^^^^^^^^^  
NotificationChannel cannot be resolved to a type

* * *

1. ERROR in C:\Users\SJGWAK\AppData\Local\Temp\android6928576046861478137sketch\src\processing\test\notifications\Notifications.java (at line 58)  
NotificationChannel channel = new NotificationChannel(CHANNEL\_ID, name, importance);  
^^^^^^^^^^^^^^^^^^^  
NotificationChannel cannot be resolved to a type

* * *

1. ERROR in C:\Users\SJGWAK\AppData\Local\Temp\android6928576046861478137sketch\src\processing\test\notifications\Notifications.java (at line 69)  
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getContext(), CHANNEL\_ID)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
The constructor NotificationCompat.Builder(Context, String) is undefined

* * *

9 problems (6 errors, 3 warnings)

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [July 19, 2018, 9:01pm UTC](https://discourse.processing.org/t/android-notifications/1914/5 "2018-07-19T21:01:52Z")

</div>

![tt](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/ec608bf9fc0ebe535b7454641aa6d4abd325de2d.jpg)

---

<div class="post-metadata">

**Author:** ![dan850](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dan850](https://discourse.processing.org/u/dan850)\
**Post date:** [July 19, 2018, 11:16pm UTC](https://discourse.processing.org/t/android-notifications/1914/6 "2018-07-19T23:16:56Z")

</div>

Hi @GWAK

> [@GWAK](#):
>
> (post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

Just to be sure, did you post this comment or was it automatically generated?

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 20, 2018, 4:56am UTC](https://discourse.processing.org/t/android-notifications/1914/7 "2018-07-20T04:56:46Z")

</div>

Notice you have warnings and errors. You can ignore the warnings. You need to focus on the errors. You first attempt is to google these errors as this is exactly what most people here will do when they try to help. Give it a try and see if you can find the solution yourself first, as these problems are likely common and already have some suggestions on how to resolve them.

For instance:

> [@GWAK](#):
>
> The import android.app.NotificationChannel cannot be resolved

Check: [java - Android studio Cannot resolve symbol 'NotificationChannel' - Stack Overflow](https://stackoverflow.com/questions/46155562/android-studio-cannot-resolve-symbol-notificationchannel)

For error #5 above:

> [android - Cannot be resolved or is not a field for SUPPORTED\_ABIS,FLAVOR & VERSION\_CODES.LOLLIPOP - Stack Overflow](https://stackoverflow.com/questions/28528129/cannot-be-resolved-or-is-not-a-field-for-supported-abis-flavor-version-codes-l)  
> [Build.VERSION\_CODES &nbsp;|&nbsp; Android Developers](https://developer.android.com/reference/android/os/Build.VERSION_CODES)

And so on.

Kf

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 20, 2018, 5:07am UTC](https://discourse.processing.org/t/android-notifications/1914/8 "2018-07-20T05:07:57Z")

</div>

Also here is the manifest. You do not need to write your own manifest. JUst use the one provided by Processing Android.

Kf

```nohighlight
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="">
    <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="26"/>
    <application android:icon="@drawable/icon" android:label="">
        <activity android:name=".MainActivity" android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

```

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [July 20, 2018, 12:32pm UTC](https://discourse.processing.org/t/android-notifications/1914/9 "2018-07-20T12:32:50Z")

</div>

@dan850

Hello, ^^  
It is a mistake. Thank you.

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [July 20, 2018, 1:21pm UTC](https://discourse.processing.org/t/android-notifications/1914/10 "2018-07-20T13:21:21Z")

</div>

@kfrajer @Andres

It’s a genius. Thank you very much. It has been resolved.  
The conclusion is that API26 + works.  
Thanks.

 ![%ED%95%B4%EA%B2%B0](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/5d9bde613e755b5d0d5c5873a6cd49dced25e422.jpg)

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [May 7, 2019, 3:50am UTC](https://discourse.processing.org/t/android-notifications/1914/11 "2019-05-07T03:50:32Z")

</div>

@kfrajer  
@Andres

Thanks to you, I was able to finish.  
Thank you.

[![]( " - YouTube") ](https://www.youtube.com/watch?v=4fRD4DI0Jko)
