2015-01-07 14:00:18 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge;
|
|
|
|
|
|
|
|
import android.app.Notification;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.service.notification.NotificationListenerService;
|
|
|
|
import android.service.notification.StatusBarNotification;
|
2015-01-22 22:49:50 +01:00
|
|
|
import android.util.Log;
|
2015-01-07 14:00:18 +01:00
|
|
|
|
|
|
|
public class NotificationListener extends NotificationListenerService {
|
|
|
|
|
|
|
|
private String TAG = this.getClass().getSimpleName();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNotificationPosted(StatusBarNotification sbn) {
|
|
|
|
Notification notification = sbn.getNotification();
|
2015-01-18 22:44:38 +01:00
|
|
|
|
|
|
|
/* do not display messages from "android"
|
|
|
|
* This includes keyboard selection message, usb connection messages, etc
|
|
|
|
* Hope it does not filter out too much, we will see...
|
|
|
|
*/
|
2015-01-22 22:49:50 +01:00
|
|
|
String source = sbn.getPackageName();
|
2015-01-24 12:21:15 +01:00
|
|
|
Log.i(TAG, source);
|
|
|
|
|
|
|
|
if (source.equals("android") ||
|
|
|
|
source.equals("com.android.dialer") ||
|
2015-01-26 18:52:19 +01:00
|
|
|
source.equals("com.fsck.k9") ||
|
2015-01-24 12:21:15 +01:00
|
|
|
source.equals("com.android.mms")) {
|
2015-01-18 22:44:38 +01:00
|
|
|
return;
|
2015-01-24 12:21:15 +01:00
|
|
|
}
|
2015-01-18 22:44:38 +01:00
|
|
|
|
2015-01-24 12:21:15 +01:00
|
|
|
Log.i(TAG, "Processing notification from source " + source);
|
2015-01-22 22:49:50 +01:00
|
|
|
|
2015-01-07 14:00:18 +01:00
|
|
|
Bundle extras = notification.extras;
|
2015-01-26 18:52:19 +01:00
|
|
|
String title = extras.getCharSequence(Notification.EXTRA_TITLE).toString();
|
|
|
|
|
2015-01-12 00:35:15 +01:00
|
|
|
String content = "";
|
2015-01-26 18:52:19 +01:00
|
|
|
if (extras.containsKey(Notification.EXTRA_TEXT)) {
|
|
|
|
CharSequence contentCS = extras.getCharSequence(Notification.EXTRA_TEXT);
|
|
|
|
if (contentCS != null) {
|
|
|
|
content = contentCS.toString();
|
|
|
|
}
|
|
|
|
}
|
2015-01-12 00:35:15 +01:00
|
|
|
|
|
|
|
if (content != null) {
|
|
|
|
Intent startIntent = new Intent(NotificationListener.this, BluetoothCommunicationService.class);
|
2015-01-24 12:21:15 +01:00
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_GENERIC);
|
2015-01-12 00:35:15 +01:00
|
|
|
startIntent.putExtra("notification_title", title);
|
2015-01-24 12:21:15 +01:00
|
|
|
startIntent.putExtra("notification_body", content);
|
2015-01-12 00:35:15 +01:00
|
|
|
startService(startIntent);
|
|
|
|
}
|
2015-01-07 14:00:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNotificationRemoved(StatusBarNotification sbn) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|