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();
|
|
|
|
if (source.equals("android") || source.equals("com.android.dialer"))
|
2015-01-18 22:44:38 +01:00
|
|
|
return;
|
|
|
|
|
2015-01-22 22:49:50 +01:00
|
|
|
Log.i(TAG, sbn.getPackageName());
|
|
|
|
|
2015-01-07 14:00:18 +01:00
|
|
|
Bundle extras = notification.extras;
|
2015-01-12 00:35:15 +01:00
|
|
|
String title = extras.getString(Notification.EXTRA_TITLE);
|
|
|
|
String content = "";
|
|
|
|
if (extras.containsKey(Notification.EXTRA_TEXT))
|
|
|
|
content = extras.getString(Notification.EXTRA_TEXT);
|
|
|
|
|
2015-01-18 22:44:38 +01:00
|
|
|
|
2015-01-12 00:35:15 +01:00
|
|
|
if (content != null) {
|
|
|
|
Intent startIntent = new Intent(NotificationListener.this, BluetoothCommunicationService.class);
|
2015-01-18 01:10:44 +01:00
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_SENDMESSAGE);
|
2015-01-12 00:35:15 +01:00
|
|
|
startIntent.putExtra("notification_title", title);
|
|
|
|
startIntent.putExtra("notification_content", content);
|
|
|
|
startService(startIntent);
|
|
|
|
}
|
2015-01-07 14:00:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNotificationRemoved(StatusBarNotification sbn) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|