Bonjour à tous !
J'essaie de faire une requête GetHTML afin de récupérer, en local, un fichier html et l'afficher dans une webview (j'adapterai le code pour qu'il s'adapte à un serveur un peu plus tard). Ce code ne me retourne aucune erreur, cependant je n'ai rien qui s'affiche à l'écran. J'ai également essayé avec 10.0.0.2, cela ne donne aucun résultat non plus. Des idées, suggestions, critiques ?
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 public class SearchActivity extends Activity { public static String getFile(String url) throws ClientProtocolException, IOException, URISyntaxException { StringBuffer stringbuffer = new StringBuffer(""); BufferedReader bufferedreader = null; try { //allow HTTPGet request HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(); URI uri = new URI(url); httpget.setURI(uri); HttpResponse httpresponse = httpclient.execute(httpget); //execute HTTP client InputStream inputstream = httpresponse.getEntity().getContent(); //put the response in a Inputstream bufferedreader = new BufferedReader(new InputStreamReader(inputstream)); String ligneCode = bufferedreader.readLine(); //read the buffer line by line and stock it in stringbuffer while (ligneCode != null) { stringbuffer.append(ligneCode); stringbuffer.append("\n"); ligneCode = bufferedreader.readLine(); } } catch (Exception e) { System.out.println("error"); } finally //in all cases close the buffer if != null { if (bufferedreader != null) { try { bufferedreader.close(); } catch (IOException e) { System.out.println("error : "); } } } return stringbuffer.toString(); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search); final WebView webView = (WebView)findViewById(R.id.webView); WebSettings webSettings = webView.getSettings(); try { String file = getFile("http://127.0.0.1/Maison%20du%20Riz%20360/C1416-MaisonduRiz-M7912-01_html5.html"); webSettings.setJavaScriptEnabled(true); webView.loadUrl(file); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } } public boolean onCreateOptionsMenu (Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
Partager