diff --git a/README.md b/README.md index c4b436105..8734ebf8c 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,10 @@ USE IT AT YOUR OWN RISK. It will problably not work. And if it works it will annoy you more than it helps you ;) Features: -* Notification for incoming calls with caller name and number -* SMS notification with sender name -* Generic Notificaions (android system and telephony notifications filtered out) +* Incoming calls (caller, phone number) +* SMS notification (sender, body) +* K-9 Mail notification support (sender, subject, preview) +* Support for generic botificaions (above filtered out) Known Issues: @@ -22,8 +23,6 @@ Known Issues: * Phone calls that are taken or rejected both count as rejected to make the Pebble stop vibrating. (No in-call display yet) * No outgoing call support (No in-call display yet) -* Complex notifications (eg. K-9 Mail) do not work yet, maybe we should implement - special K-9 Mail support? Or just support taking complex notificaion apart? * Notifications are not properly queued, if two arrive at about the same time, one of them will get lost (TODO: confirm) * Android 4.4+ only, we can only change this by not handling generic diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 32642ee57..d61159900 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,6 +6,7 @@ + + + + + + + diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java index 1bf2a0e2e..f50a42fb3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java @@ -37,6 +37,8 @@ public class BluetoothCommunicationService extends Service { = "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.notification_generic"; public static final String ACTION_NOTIFICATION_SMS = "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.notification_sms"; + public static final String ACTION_NOTIFICATION_EMAIL + = "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.notification_email"; public static final String ACTION_INCOMINGCALL = "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.incomingcall"; public static final String ACTION_SETTIME @@ -57,6 +59,11 @@ public class BluetoothCommunicationService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { + + if (!intent.getAction().equals(ACTION_START) && !intent.getAction().equals(ACTION_STOP) && mBtSocketIoThread == null) { + return START_STICKY; + } + if (intent.getAction().equals(ACTION_START)) { Intent notificationIntent = new Intent(this, ControlCenter.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK @@ -126,34 +133,29 @@ public class BluetoothCommunicationService extends Service { } else if (intent.getAction().equals(ACTION_NOTIFICATION_GENERIC)) { String title = intent.getStringExtra("notification_title"); String body = intent.getStringExtra("notification_body"); - if (mBtSocketIoThread != null) { - byte[] msg = PebbleProtocol.encodeSMS(title, body); - mBtSocketIoThread.write(msg); - } + byte[] msg = PebbleProtocol.encodeSMS(title, body); + mBtSocketIoThread.write(msg); } else if (intent.getAction().equals(ACTION_NOTIFICATION_SMS)) { String sender = intent.getStringExtra("notification_sender"); String body = intent.getStringExtra("notification_body"); String senderName = getContactDisplayNameByNumber(sender); - - if (mBtSocketIoThread != null) { - byte[] msg = PebbleProtocol.encodeSMS(senderName, body); - mBtSocketIoThread.write(msg); - } + byte[] msg = PebbleProtocol.encodeSMS(senderName, body); + mBtSocketIoThread.write(msg); + } else if (intent.getAction().equals(ACTION_NOTIFICATION_EMAIL)) { + String sender = intent.getStringExtra("notification_sender"); + String subject = intent.getStringExtra("notification_subject"); + String body = intent.getStringExtra("notification_body"); + byte[] msg = PebbleProtocol.encodeEmail(sender, subject, body); + mBtSocketIoThread.write(msg); } else if (intent.getAction().equals(ACTION_INCOMINGCALL)) { String phoneNumber = intent.getStringExtra("incomingcall_phonenumber"); byte phoneState = intent.getByteExtra("incomingcall_state", (byte) 0); - String callerName = getContactDisplayNameByNumber(phoneNumber); - - if (mBtSocketIoThread != null) { - byte[] msg = PebbleProtocol.encodeIncomingCall(phoneNumber, callerName, phoneState); - mBtSocketIoThread.write(msg); - } + byte[] msg = PebbleProtocol.encodeIncomingCall(phoneNumber, callerName, phoneState); + mBtSocketIoThread.write(msg); } else if (intent.getAction().equals(ACTION_SETTIME)) { - if (mBtSocketIoThread != null) { - byte[] msg = PebbleProtocol.encodeSetTime(-1); - mBtSocketIoThread.write(msg); - } + byte[] msg = PebbleProtocol.encodeSetTime(-1); + mBtSocketIoThread.write(msg); } return START_STICKY; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/K9Receiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/K9Receiver.java new file mode 100644 index 000000000..9c506988f --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/K9Receiver.java @@ -0,0 +1,39 @@ +package nodomain.freeyourgadget.gadgetbridge; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.net.Uri; + +public class K9Receiver extends BroadcastReceiver { + + private final String TAG = this.getClass().getSimpleName(); + private final Uri k9Uri = Uri.parse("content://com.fsck.k9.messageprovider/inbox_messages"); + + @Override + public void onReceive(Context context, Intent intent) { + // get sender and subject from the Intent + String sender = intent.getStringExtra("com.fsck.k9.intent.extra.FROM"); + String subject = intent.getStringExtra("com.fsck.k9.intent.extra.SUBJECT"); + + // get preview from K9 Content Provider, unfortunately this does not come with the Intent + String[] whereParameters = {intent.getData().toString()}; + String[] messagesProjection = { + "preview" + }; + + Cursor c = context.getContentResolver().query(k9Uri, null, "uri=?", whereParameters, " LIMIT 1"); + c.moveToFirst(); + String preview = c.getString(c.getColumnIndex("preview")); + c.close(); + + Intent startIntent = new Intent(context, BluetoothCommunicationService.class); + startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_EMAIL); + startIntent.putExtra("notification_sender", sender); + startIntent.putExtra("notification_subject", subject); + startIntent.putExtra("notification_body", preview); + + context.startService(startIntent); + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/NotificationListener.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/NotificationListener.java index 1a7215075..a9b71e0a8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/NotificationListener.java @@ -34,6 +34,7 @@ public class NotificationListener extends NotificationListenerService { if (source.equals("android") || source.equals("com.android.dialer") || + source.equals("com.fsck.k9") || source.equals("com.android.mms")) { return; } @@ -41,10 +42,15 @@ public class NotificationListener extends NotificationListenerService { Log.i(TAG, "Processing notification from source " + source); Bundle extras = notification.extras; - String title = extras.getString(Notification.EXTRA_TITLE); + String title = extras.getCharSequence(Notification.EXTRA_TITLE).toString(); + String content = ""; - if (extras.containsKey(Notification.EXTRA_TEXT)) - content = extras.getString(Notification.EXTRA_TEXT); + if (extras.containsKey(Notification.EXTRA_TEXT)) { + CharSequence contentCS = extras.getCharSequence(Notification.EXTRA_TEXT); + if (contentCS != null) { + content = contentCS.toString(); + } + } if (content != null) { Intent startIntent = new Intent(NotificationListener.this, BluetoothCommunicationService.class);