Notifications [demo]
Notifications [demo]
I discovered time ago how to make notifications, and I’ve been searching for a good way to use them…but I failed. A launcher is not something that normally need notifications.
So, as you all have good ideas, I made a demo of how to make a notification, a simple script with almost every line commented, and ready to edit if you want to test. (I’ll continue thinking myself too)
Be creative 🙂
]]>« Hello everybody and a very good end of year party 😄🎉🎊 (Previous Post)
(Next Post) Bug Report »
< ![CDATA[
//bind classes
LL.bindClass(“android.app.Notification”);
LL.bindClass(“android.app.NotificationManager”);
LL.bindClass(“android.content.Context”);
LL.bindClass(“android.app.PendingIntent”);
LL.bindClass(“android.R”);
//vars used also in the returned functions
var cntx=LL.getContext();//if you need a ‘context’ for a java function, this is probably what you need.
var nm=cntx.getSystemService(Context.NOTIFICATION_SERVICE);//returns the service used to work with notifications
//if data passed, evaluate the data as code
if((data=LL.getEvent().getData())!=null){
eval(“function toeval(){“+data+”\n}”);
toeval();//encapsulating the code inside a function instead of evaluating it directly allows to make alerts and such
return;
}
//if there wasn’t data, create the notification
var id=0;//single identifier for each pending intent, used in the helper function
//create the notification from a builder
var n=Notification.Builder(cntx)//start the builder
.setContentTitle(“A notification”)//title
.setContentText(“This is a demo of how to make a notification.”)//main text
.setContentInfo(“notification demo”)//information
.setSmallIcon(R.drawable.ic_dialog_info)//small icon
.setContentIntent(makeintent(“main();”))//when launch
.setSubText(“commentary”)//secondary text
.setDeleteIntent(makeintent(“dismissed();”))//when dismissed
.setAutoCancel(false)//set to true to cancel when clicking
.addAction(R.drawable.ic_menu_save,”Accept”,makeintent(“accept();”))//extra button
.addAction(0,”direct”,makeintent(“alert(‘This alert is evaluated directly’);”))//extra button
.addAction(R.drawable.ic_menu_close_clear_cancel,”Cancel”,makeintent(“cancel();”))//another extra button
//you can add more things like sound, vibration, color…
//search ‘notification.builder’
.build();//finish the builder and returns a ready notification
nm.notify(0,n);//show the notification. If you want to show more than one you need to set a different first number for each
//help function to make pending notifications
function makeintent(data){
var intent=new Intent().getIntent(“#Intent;component=net.pierrox.lightning_launcher_extreme/net.pierrox.lightning_launcher.activities.Dashboard;i.a=35;end”)//’launch a script’ shortcut
intent.putExtra(‘d’,LL.getCurrentScript().getId()+”/”+data);//which script and data
return PendingIntent.getActivity(cntx,id++,intent,0x8000000);//the pending intent ready to be used. each one with different id, and flag to refresh existing one
}
//functions, used to better structure of the code
function main(){
alert(“Notification clicked, now…do things”);
//things
}
function accept(){
alert(“accepted”);
nm.cancel(0);//this removes the notification
}
function cancel(){
Android.makeNewToast(“canceled”,true).show();
nm.cancel(0);//this removes the notification
}
function dismissed(){
Android.makeNewToast(“Vital testing apparatus destroyed.”,false).show();
//if you didn’t get it, it’s from Portal 😉
}
]]>
< ![CDATA[
Very interesting!
Added to my APIs todo list 🙂
]]>
< ![CDATA[
Wow
]]>
< ![CDATA[
Awesome! Like you, I’m not sure what notifications could be used for a launcher, but it’s always nice to have the option available.
]]>
< ![CDATA[
I am thinking at one particular use: you could make some sort of “Notification launcher”. I don’t recall exactly but I think there was one on iOS before it get removed by Apple, and there are probably more than one in the Play Store.
]]>
< ![CDATA[
can bigTitle be added? Can this script be called from Tasker as an alternative to Tasker’s included notify actions?
]]>
< ![CDATA[
Not sure what do you mean with bigTitle
It can be called, but I don’t know well how. (There is a tasker api, but I never tried it)
The problem could be the context, I mean, if you want the notification to do something, the script I posted will run with the privileges of the launcher, so it will always open the launcher first.
Pierre Hébert​ is it possible somehow to select a context different of the launcher so that, for example, displaying only a toast don’t open the launcher first?
]]>
< ![CDATA[
There is a great prog from astoncheah for notifs : C Notice
You can choose to open directly the prog or a little window first
]]>
< ![CDATA[
TrianguloYÂ not without a specific support from the launcher. It probably need a transparent activity that is able to execute scripts (and possibly other actions) but has no UI.
]]>
< ![CDATA[
And…will it come someday? :)
]]>
< ![CDATA[
Honestly I prefer to say “I don’t know yet”!
Sometimes I say yes, and sometimes I implement other features first…
]]>