这是我的代码的一部分:
try {
// make json string, try also hamburger
//String json = "{\"pid\":\"name\",\"price\":\"created_at\",\"updated_at\":3}";
// send as http get request
URL url = new URL("http://smsas.eu/dm/get_all_products.php");
URLConnection conn = url.openConnection();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
//System.out.println(line);
JSONObject nodeRoot = new JSONObject(line);
JSONArray nodeStats = nodeRoot.getJSONArray("products");
for(int i=0; i < nodeStats.length();i++){
String sSDR = nodeStats.getJSONObject(i).getString("name");
System.out.println(sSDR);
tt.setText(sSDR);
}
}
rd.close();
} catch (Exception e) {
tt.setText("ERR");
e.printStackTrace();
}
当我在虚拟设备上运行应用程序时,它正在运行,但是当我在手机上运行时 - 不是。我已经添加了互联网许可。