We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi! I'd like to have notifications in my app, but I know that the way in which a processing sketch works on Android is a bit different; I've been able to include toast notifications (that we can see when the app is on the screen), using the Android constructors.
A piece of code for Toast Notifications:
// The Looper is necessary for displaying Toast Notifications
import android.os.Looper;
import android.widget.Toast;
class TOASTnotifications extends Thread {
// Text of the notification
String txt = t;
// Duration of the notification
int time = n;
public TOASTnotifications (String t, int n) {
txt= t;
time = n;
}
public void start() {
super.start();
}
//@Override
public void run() {
Looper.prepare();
Toast.makeText(this, txt, time).show();
Looper.loop();
}
}
But I'd like to see notifications in the android notification center, and then return to the app when I click on them.
Thanks in advance for any help
Answers
The Android Notifications Tutorial is probably a good place to start. I don't see any conflicts with Processing from a quick read-through...
The notifications in the tutorial weren't available until Android 3.0, although a support library is available. I'm not sure how difficult it would be to integrate the support library into Processing... on the other hand, I'm not sure how difficult it would be to install the 3.0 APIs and target API level 11+. The latter solution will probably be easier, assuming that you don't need to support Android 2.3.3.
When you need to reference the target
Activity
(i.e.ResultActivity.class
), you may be somewhat confused... in Processing, it should be as simple as passingsketchName.class
(wheresketchName
is the name of your sketch). This is because Processing wraps your sketch in a subclass ofActivity
with the name of your sketch.There will probably be lots of imports for the notification APIs, but you're probably used to this if you have dealt with toasts in the past.
This is an area of Android development (both Processing and native) that I haven't tried to use before. I can only wish you good luck...
Thanks calsign! I've already read that Tutorial, but it's perfect if you develop directly for Android; probably I need to understand how Processing allow me to create different android Activities.
How far did it go!! I wanna make something similar how do I do it? I wanna push a notification, even when the app is closed and not working. Please help me with this!!
@riccardoch===
What Callsign says (and the Android ref.) is not possible with P3:: it does not allow to add other activities in the Manifest and if you create one by code, with the standard way (Intent) and adding this activity as a class you get error: activity not present in the manifest....
"Processing only supports a single Activity in the AndroidManifest.xml\n" + "file. Only the first activity entry will be updated, and you better \n" + "hope that's the right one, smartypants.";
you can read this here:
https://github.com/processing/processing-android/blob/master/src/processing/mode/android/Manifest.java :(