@Override public void onReceive(Context context, Intent intent) { /* * no name setting, so don't bother pulling in SMS's yet or The user doesn't want us pulling in his SMS. */ Logger.d("HikeMessageReceiver", System.currentTimeMillis() + ""); Logger.d("HikeMessageReceiver", "message received"); // If the User is not authenticated and the GCMID is not sent to the server and the user is // connected. HikeSharedPreferenceUtil mprefs = HikeSharedPreferenceUtil.getInstance(); if (Utils.isUserOnline(context) && (!Utils.isUserAuthenticated(context)) && !mprefs.getData(HikeMessengerApp.GCM_ID_SENT_PRELOAD, false)) { Intent in = new Intent(HikeService.REGISTER_TO_GCM_ACTION); mprefs.saveData(HikeConstants.REGISTER_GCM_SIGNUP, HikeConstants.REGISTEM_GCM_BEFORE_SIGNUP); LocalBroadcastManager.getInstance(context.getApplicationContext()).sendBroadcast(in); return; } if (!Utils.isUserSignedUp(context, false) || !PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(HikeConstants.RECEIVE_SMS_PREF, false)) { return; } Logger.d(getClass().getSimpleName(), "Received SMS message"); Bundle extras = intent.getExtras(); if (extras != null) { Logger.d(getClass().getSimpleName(), "Received SMS message with extras " + extras.keySet()); Object[] extra = (Object[]) extras.get("pdus"); Logger.d(getClass().getSimpleName(), "Extras length is " + extra.length); for (int i = 0; i < extra.length; ++i) { SmsMessage sms = SmsMessage.createFromPdu((byte[]) extra[i]); String body = sms.getMessageBody(); long timestamp = sms.getTimestampMillis() / 1000; String from = sms.getOriginatingAddress(); ContactInfo contactInfo = HikeMessengerApp.getContactManager().getContact(from, true, true); if (contactInfo == null) { Logger.d( getClass().getSimpleName(), "Ignoring SMS message because contact not in addressbook phone_no=" + from); return; } try { JSONObject msg = new JSONObject(); msg.put(HikeConstants.TYPE, HikeConstants.MqttMessageTypes.MESSAGE); msg.put(HikeConstants.FROM, contactInfo.getMsisdn()); JSONObject data = new JSONObject(); data.put(HikeConstants.SMS_MESSAGE, body); data.put(HikeConstants.TIMESTAMP, timestamp); data.put(HikeConstants.MESSAGE_ID, makeSMSId(from, body, timestamp)); msg.put(HikeConstants.DATA, data); writeToNativeSMSDb(context, msg); Logger.d(getClass().getSimpleName(), "Received SMS " + msg.toString()); Intent smsReceivedIntent = new Intent(context, HikeService.class); smsReceivedIntent.putExtra(HikeConstants.Extras.SMS_MESSAGE, msg.toString()); context.startService(smsReceivedIntent); this.abortBroadcast(); } catch (JSONException e) { Logger.e(getClass().getSimpleName(), "Invalid data for SMS message", e); return; } } } }
public JavascriptBridge(Activity activity, WebView mWebView) { this.mWebView = mWebView; weakActivity = new WeakReference<Activity>(activity); this.mHandler = new Handler(HikeMessengerApp.getInstance().getMainLooper()); }