|
@ -2,7 +2,6 @@ package com.speculos.myapplicationoc; |
|
|
|
|
|
|
|
|
import android.app.Activity; |
|
|
import android.app.Activity; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
import android.util.Log; |
|
|
|
|
|
import android.view.View; |
|
|
import android.view.View; |
|
|
import android.widget.Button; |
|
|
import android.widget.Button; |
|
|
import android.widget.EditText; |
|
|
import android.widget.EditText; |
|
@ -14,6 +13,12 @@ import androidx.annotation.Nullable; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.util.regex.Pattern; |
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
|
|
import okhttp3.MediaType; |
|
|
|
|
|
import okhttp3.OkHttpClient; |
|
|
|
|
|
import okhttp3.Request; |
|
|
|
|
|
import okhttp3.RequestBody; |
|
|
|
|
|
import okhttp3.Response; |
|
|
|
|
|
|
|
|
public class TagDetectedActivityAdmin extends Activity { |
|
|
public class TagDetectedActivityAdmin extends Activity { |
|
|
|
|
|
|
|
|
String hexa_id, mail, username; |
|
|
String hexa_id, mail, username; |
|
@ -98,16 +103,29 @@ public class TagDetectedActivityAdmin extends Activity { |
|
|
|
|
|
|
|
|
// On peut maintenant link le bracelet grace à l'hexa_id et l'idClient
|
|
|
// On peut maintenant link le bracelet grace à l'hexa_id et l'idClient
|
|
|
try { |
|
|
try { |
|
|
response = APICommandes.postMethod(srvURL + "/api/bracelets","{\"nfcId\": \"" + hexa_id + "\", \"client\": \"/api/clients/" + idClient + "\", \"state\" :"+0+"}"); |
|
|
// response = APICommandes.postMethod(srvURL + "/api/bracelets","{\"nfcId\": \"" + hexa_id + "\", \"client\": \"/api/clients/" + idClient + "\", \"state\" :"+0+"}");
|
|
|
Toast.makeText(TagDetectedActivityAdmin.this, "Message: " + response, Toast.LENGTH_LONG).show(); |
|
|
|
|
|
Log.d("DEBUG-CLIENT",response); |
|
|
OkHttpClient client = new OkHttpClient().newBuilder() |
|
|
|
|
|
.build(); |
|
|
|
|
|
MediaType mediaType = MediaType.parse("application/json"); |
|
|
|
|
|
RequestBody body = RequestBody.create(mediaType, "{\"nfcId\": \""+hexa_id+"\",\"client\": \"/api/clients/"+idClient+"\",\"state\": 0}"); |
|
|
|
|
|
Request request = new Request.Builder() |
|
|
|
|
|
.url(srvURL + "/api/bracelets") |
|
|
|
|
|
.method("POST", body) |
|
|
|
|
|
.addHeader("Content-Type", "application/json") |
|
|
|
|
|
.build(); |
|
|
|
|
|
Response responseHttp = client.newCall(request).execute(); |
|
|
|
|
|
|
|
|
|
|
|
if (responseHttp.code() == 400) { |
|
|
try{ |
|
|
try{ |
|
|
maListeJson = new JsonTraductor(response); |
|
|
maListeJson = new JsonTraductor(responseHttp.body().string()); |
|
|
String violationMessage = ((maListeJson.getJsonData("violations", 0))); |
|
|
String violationMessage = ((maListeJson.getJsonData("violations", 0))); |
|
|
Toast.makeText(TagDetectedActivityAdmin.this, "Message: "+violationMessage, Toast.LENGTH_LONG).show(); |
|
|
maListeJson = new JsonTraductor(violationMessage); |
|
|
|
|
|
violationMessage = ((maListeJson.getJsonData("message", 0))); |
|
|
|
|
|
Toast.makeText(TagDetectedActivityAdmin.this, "ID NFC: "+violationMessage, Toast.LENGTH_LONG).show(); |
|
|
|
|
|
|
|
|
} catch (Exception e) {} |
|
|
} catch (Exception e) {} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|