ConnectionFragment.java
1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.example.app_10p5;
import android.content.Intent;
import android.content.SharedPreferences;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import java.net.URL;
import java.util.HashMap;
/**
* Created by Jean-loup Beaussart on 05/05/2016.
*/
public class ConnectionFragment extends NFC {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.layout_connection, container, false);
}
@Override
public void handleIntent(Intent intent) {
try{
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
URL url = new URL(settings.getString("server_address", null) + "api/utilisateur/connexion");
HashMap<String, String> param = new HashMap<String, String>();
String id_carte = ByteArrayToHexString(intent.getByteArrayExtra(NfcAdapter.EXTRA_ID));
param.put("idCarte", id_carte);
NetworkThread nt = new NetworkThread(url, param);
nt.delegate = (MainActivite) getActivity();
nt.execute();
}
catch (Throwable t) {
Toast.makeText(getActivity(), "Erreur: " + t.toString(), Toast.LENGTH_LONG).show();
System.out.println("Exception: " + t.toString());
}
}
}