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
| public class SearchActivity extends Activity {
public static String getFile(String url) throws IOException
{
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url); // will throw IllegalArgumentException if url is badly formed
HttpResponse httpresponse = httpclient.execute(httpget);
if (httpresponse.getStatusLine().getStatusCode() >= 400)
throw new IOException(httpresponse.getStatusLine().getReasonPhrase());
return EntityUtils.toString(httpresponse.getEntity());
}
@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://10.0.2.2/MaisonduRiz360/C1416-MaisonduRiz-M7912-01_html5.html");
webSettings.setJavaScriptEnabled(true);
webView.loadUrl(file);
}
catch (Exception ex)
{
Log.e("GetFile", "Erreur de récuperation...", ex);
Toast.makeText(this, "erreur de récupération du fichier", Toast.LENGTH_LONG).show();
}
}
public boolean onCreateOptionsMenu (Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
} |