2017-07-07 89 views
0

發送Android和Arduino的之間的數據I程序我Arduino的,當我在平板型192.168.4.1的Arduino給我Html頁面,但是當我使用此代碼我不能接收到任何數據,我得到這個錯誤:通過Wifi

java.net.MalformedURLException: Protocol not found: 192.168.4.1

我該如何解決這個問題?

private void getdata(){ 

    try { 
     URL url = new URL("192.168.4.1"); 
     HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
     conn.connect(); 
     InputStream inputStream = conn.getInputStream(); 
     InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8"); 
     BufferedReader bufferedReader = new BufferedReader(inputStreamReader); 

     String data = "", line = ""; 
     StringBuffer buffer = new StringBuffer(); 
     while ((line = bufferedReader.readLine()) != null) { 
      // data += line + "\n"; 
      buffer.append(line + "\n"); 
     } 
     Thread.sleep(4000); 
    } //end try 

    Log.e("errrorrrrrrrrrrrr", e.toString()); 
     e.printStackTrace(); 

    } catch (IOException e) { 
     e.printStackTrace(); 
    } catch (InterruptedException e) { 
     e.printStackTrace(); 
    } 
} 

回答

0

嘗試添加http://到您的網址:

URL url = new URL("http://192.168.4.1"); 
+0

我這樣做,但它沒有工作 –

+0

你使用任何端口?嘗試在末尾添加'/' –

+0

現在我測試這些 URL url = new URL(「http://192.168.4.1:80」); URL url = new URL(「http://192.168.4.1/」); 但沒有工作 –