package de.esolutions4you.nlservice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Events;
@Version(1.5f)
@ShortName("NLService")
public class NLService extends NotificationListenerService {
//private BA ba=null;
//private String eventName="";
private String TAG = this.getClass().getSimpleName();
private NLServiceReceiver nlservicereciver;
@Override
public void onCreate() {
super.onCreate();
//nlservicereciver = new NLServiceReceiver();
//IntentFilter filter = new IntentFilter();
//filter.addAction("de.esolutions4you.bubblelauncher.srvnotificationlistener");
//registerReceiver(nlservicereciver,filter);
}
@Override
public void onDestroy() {
super.onDestroy();
//unregisterReceiver(nlservicereciver);
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
Log.i(TAG,"********** onNotificationPosted");
Log.i(TAG,"ID :" + sbn.getId() + "t" + sbn.getNotification().tickerText + "t" + sbn.getPackageName());
Intent i = new Intent("de.esolutions4you.bubblelauncher.srvnotificationlistener");
i.putExtra("notification_event","onNotificationPosted :" + sbn.getPackageName() + "n");
sendBroadcast(i);
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
Log.i(TAG,"********** onNOtificationRemoved");
Log.i(TAG,"ID :" + sbn.getId() + "t" + sbn.getNotification().tickerText +"t" + sbn.getPackageName());
Intent i = new Intent("de.esolutions4you.bubblelauncher.srvnotificationlistener");
i.putExtra("notification_event","onNotificationRemoved :" + sbn.getPackageName() + "n");
sendBroadcast(i);
}
class NLServiceReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getStringExtra("command").equals("clearall")){
NLService.this.cancelAllNotifications();
}
else if(intent.getStringExtra("command").equals("list")){
Intent i1 = new Intent("de.esolutions4you.bubblelauncher.srvnotificationlistener");
i1.putExtra("notification_event","=====================");
sendBroadcast(i1);
int i=1;
for (StatusBarNotification sbn : NLService.this.getActiveNotifications()) {
Intent i2 = new Intent("de.esolutions4you.bubblelauncher.srvnotificationlistener");
i2.putExtra("notification_event",i +" " + sbn.getPackageName() + "n");
sendBroadcast(i2);
i++;
}
Intent i3 = new Intent("de.esolutions4you.bubblelauncher.srvnotificationlistener");
i3.putExtra("notification_event","===== Notification List ====");
sendBroadcast(i3);
}
}
}
}