2017-07-07 49 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/”); 但没有工作 –