2015-01-24 12:21:15 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge;
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2015-03-06 14:00:56 +01:00
|
|
|
import android.content.SharedPreferences;
|
2015-01-24 12:21:15 +01:00
|
|
|
import android.os.Bundle;
|
2015-03-04 23:47:47 +01:00
|
|
|
import android.os.PowerManager;
|
2015-03-06 14:00:56 +01:00
|
|
|
import android.preference.PreferenceManager;
|
2015-01-24 12:21:15 +01:00
|
|
|
import android.telephony.SmsMessage;
|
|
|
|
|
|
|
|
public class SMSReceiver extends BroadcastReceiver {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2015-03-04 23:47:47 +01:00
|
|
|
|
2015-03-06 14:00:56 +01:00
|
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
if (!sharedPrefs.getBoolean("notifications_sms", true)) {
|
2015-03-04 23:47:47 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-03-06 14:00:56 +01:00
|
|
|
if (!sharedPrefs.getBoolean("notifications_sms_whenscreenon", false)) {
|
|
|
|
PowerManager powermanager = (PowerManager) context.getSystemService(context.POWER_SERVICE);
|
|
|
|
if (powermanager.isScreenOn()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-03-04 23:47:47 +01:00
|
|
|
|
2015-01-24 12:21:15 +01:00
|
|
|
Bundle bundle = intent.getExtras();
|
|
|
|
if (bundle != null) {
|
|
|
|
Object[] pdus = (Object[]) bundle.get("pdus");
|
|
|
|
for (int i = 0; i < pdus.length; i++) {
|
|
|
|
byte[] pdu = (byte[]) pdus[i];
|
|
|
|
SmsMessage message = SmsMessage.createFromPdu(pdu);
|
|
|
|
String body = message.getDisplayMessageBody();
|
|
|
|
String sender = message.getOriginatingAddress();
|
|
|
|
if (sender != null && body != null) {
|
|
|
|
Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
|
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_SMS);
|
|
|
|
startIntent.putExtra("notification_sender", sender);
|
|
|
|
startIntent.putExtra("notification_body", body);
|
|
|
|
context.startService(startIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|