这很简单我很确定,但我遗漏了一些东西。 我想用android来运行一个远程PHP文件 - 写入文本文件。 我想这样做是为了学习使用android在网络上发出请求。 我不想从PHP文件中找回任何文本,我也不想让它获取任何数据。 我只希望它能够运行。
我在我的android mainActivity文件中使用它
try {
String url = "http://cinderellagasman.com/ANDROID/connect.php";
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(new HttpGet(url));
} catch (IOException e) {
//do something here
}
但它会立即崩溃。 我只能得到这个; " PropertyFetcher:AdbCommandRejectedException获取设备模拟器-5554的属性:设备离线"在我的ADB日志中。
模拟器似乎正常工作。 我在清单文件中启用了Internet权限。 我想要运行的PHP是
`$file = "data.txt";
$handle = fopen($file, "a");
$now = date('l jS \of F Y h:i:s A');
fwrite($handle, $now."\n");
echo "hello";`
建议欢迎,我在这里基本层面,通常可以在不问的情况下找到答案..
enter code hereProcess: com.example.douglas.connect_php, PID: 2879
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.douglas.connect_php/com.example.douglas.connect_php.MainActivity}: android.os.NetworkOnMainThreadException