Browse Source

Merge pull request #87 from vernu/fix-duplicate-received-sms

fix duplicate received sms issue
pull/89/head
Israel Abebe 9 months ago
committed by GitHub
parent
commit
383cf213d8
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      android/app/build.gradle
  2. 19
      android/app/src/main/java/com/vernu/sms/services/StickyNotificationService.java

4
android/app/build.gradle

@ -11,8 +11,8 @@ android {
applicationId "com.vernu.sms" applicationId "com.vernu.sms"
minSdk 24 minSdk 24
targetSdk 32 targetSdk 32
versionCode 13
versionName "2.6.0"
versionCode 14
versionName "2.6.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

19
android/app/src/main/java/com/vernu/sms/services/StickyNotificationService.java

@ -21,7 +21,6 @@ import com.vernu.sms.helpers.SharedPreferenceHelper;
public class StickyNotificationService extends Service { public class StickyNotificationService extends Service {
private static final String TAG = "StickyNotificationService"; private static final String TAG = "StickyNotificationService";
private final BroadcastReceiver receiver = new SMSBroadcastReceiver();
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
@ -34,7 +33,7 @@ public class StickyNotificationService extends Service {
super.onCreate(); super.onCreate();
Log.i(TAG, "Service Started"); Log.i(TAG, "Service Started");
// Only register receiver and show notification if enabled in preferences
// Only show notification if enabled in preferences
boolean stickyNotificationEnabled = SharedPreferenceHelper.getSharedPreferenceBoolean( boolean stickyNotificationEnabled = SharedPreferenceHelper.getSharedPreferenceBoolean(
getApplicationContext(), getApplicationContext(),
AppConstants.SHARED_PREFS_STICKY_NOTIFICATION_ENABLED_KEY, AppConstants.SHARED_PREFS_STICKY_NOTIFICATION_ENABLED_KEY,
@ -42,11 +41,6 @@ public class StickyNotificationService extends Service {
); );
if (stickyNotificationEnabled) { if (stickyNotificationEnabled) {
IntentFilter filter = new IntentFilter();
filter.addAction(Telephony.Sms.Intents.SMS_RECEIVED_ACTION);
filter.addAction(android.telephony.TelephonyManager.ACTION_PHONE_STATE_CHANGED);
registerReceiver(receiver, filter);
Notification notification = createNotification(); Notification notification = createNotification();
startForeground(1, notification); startForeground(1, notification);
Log.i(TAG, "Started foreground service with sticky notification"); Log.i(TAG, "Started foreground service with sticky notification");
@ -65,17 +59,6 @@ public class StickyNotificationService extends Service {
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
// Only unregister if we had registered in the first place
boolean stickyNotificationEnabled = SharedPreferenceHelper.getSharedPreferenceBoolean(
getApplicationContext(),
AppConstants.SHARED_PREFS_STICKY_NOTIFICATION_ENABLED_KEY,
false
);
if (stickyNotificationEnabled) {
unregisterReceiver(receiver);
}
Log.i(TAG, "StickyNotificationService destroyed"); Log.i(TAG, "StickyNotificationService destroyed");
} }

Loading…
Cancel
Save