Search in sources :

Example 6 with NotificationSpec

use of nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec in project Gadgetbridge by Freeyourgadget.

the class PebbleReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Prefs prefs = GBApplication.getPrefs();
    if ("never".equals(prefs.getString("notification_mode_pebblemsg", "when_screen_off"))) {
        return;
    }
    if ("when_screen_off".equals(prefs.getString("notification_mode_pebblemsg", "when_screen_off"))) {
        PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (powermanager.isScreenOn()) {
            return;
        }
    }
    String messageType = intent.getStringExtra("messageType");
    if (!messageType.equals("PEBBLE_ALERT")) {
        LOG.info("non PEBBLE_ALERT message type not supported");
        return;
    }
    if (!intent.hasExtra("notificationData")) {
        LOG.info("missing notificationData extra");
        return;
    }
    NotificationSpec notificationSpec = new NotificationSpec();
    notificationSpec.id = -1;
    String notificationData = intent.getStringExtra("notificationData");
    try {
        JSONArray notificationJSON = new JSONArray(notificationData);
        notificationSpec.title = notificationJSON.getJSONObject(0).getString("title");
        notificationSpec.body = notificationJSON.getJSONObject(0).getString("body");
    } catch (JSONException e) {
        e.printStackTrace();
        return;
    }
    if (notificationSpec.title != null) {
        notificationSpec.type = NotificationType.UNKNOWN;
        String sender = intent.getStringExtra("sender");
        if ("Conversations".equals(sender)) {
            notificationSpec.type = NotificationType.CONVERSATIONS;
        } else if ("OsmAnd".equals(sender)) {
            notificationSpec.type = NotificationType.GENERIC_NAVIGATION;
        }
        GBApplication.deviceService().onNotification(notificationSpec);
    }
}
Also used : PowerManager(android.os.PowerManager) NotificationSpec(nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs)

Example 7 with NotificationSpec

use of nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec in project Gadgetbridge by Freeyourgadget.

the class SMSReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Prefs prefs = GBApplication.getPrefs();
    if ("never".equals(prefs.getString("notification_mode_sms", "when_screen_off"))) {
        return;
    }
    if ("when_screen_off".equals(prefs.getString("notification_mode_sms", "when_screen_off"))) {
        PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (powermanager.isScreenOn()) {
            return;
        }
    }
    NotificationSpec notificationSpec = new NotificationSpec();
    notificationSpec.id = -1;
    notificationSpec.type = NotificationType.GENERIC_SMS;
    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        if (pdus != null) {
            for (Object pdu1 : pdus) {
                byte[] pdu = (byte[]) pdu1;
                SmsMessage message = SmsMessage.createFromPdu(pdu);
                notificationSpec.body = message.getDisplayMessageBody();
                notificationSpec.phoneNumber = message.getOriginatingAddress();
                if (notificationSpec.phoneNumber != null) {
                    switch(GBApplication.getGrantedInterruptionFilter()) {
                        case NotificationManager.INTERRUPTION_FILTER_ALL:
                            break;
                        case NotificationManager.INTERRUPTION_FILTER_ALARMS:
                        case NotificationManager.INTERRUPTION_FILTER_NONE:
                            return;
                        case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
                            if (GBApplication.isPriorityNumber(Policy.PRIORITY_CATEGORY_MESSAGES, notificationSpec.phoneNumber)) {
                                break;
                            }
                            return;
                    }
                    GBApplication.deviceService().onNotification(notificationSpec);
                }
            }
        }
    }
}
Also used : PowerManager(android.os.PowerManager) SmsMessage(android.telephony.SmsMessage) Bundle(android.os.Bundle) NotificationSpec(nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs)

Aggregations

NotificationSpec (nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec)7 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)4 PowerManager (android.os.PowerManager)3 ArrayList (java.util.ArrayList)2 CallSpec (nodomain.freeyourgadget.gadgetbridge.model.CallSpec)2 MusicSpec (nodomain.freeyourgadget.gadgetbridge.model.MusicSpec)2 MusicStateSpec (nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec)2 NotificationType (nodomain.freeyourgadget.gadgetbridge.model.NotificationType)2 Notification (android.app.Notification)1 IntentFilter (android.content.IntentFilter)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 StatusBarNotification (android.service.notification.StatusBarNotification)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 SmsMessage (android.telephony.SmsMessage)1 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 UUID (java.util.UUID)1