在android应用程序上通过php运行python脚本
我对这一切都不熟悉,但是 我正在通过我的raspberry pi尝试一点家庭自动化,我有一个本地web服务器,可以用来打开和关闭灯,下面是php代码:在android应用程序上通过php运行python脚本,android,Android,我对这一切都不熟悉,但是 我正在通过我的raspberry pi尝试一点家庭自动化,我有一个本地web服务器,可以用来打开和关闭灯,下面是php代码: <html> <head> </head> <?php if (isset($_POST['ON'])) { exec("sudo python /home/pi/turnOn.py"); } if (isset($_POST['OFF'])) { exec("sudo python
<html>
<head>
</head>
<?php
if (isset($_POST['ON']))
{
exec("sudo python /home/pi/turnOn.py");
}
if (isset($_POST['OFF']))
{
exec("sudo python /home/pi/turnOff.py");
}
?>
<form method="post">
<button name="ON">ON</button>
<button name="OFF">OFF</button><br>
</form>
</html>
我想制作按钮(在android中),这样当在android应用程序中按下“ON”时,它会做与在php文档中按下“ON”时相同的事情。我应该编写什么java方法来实现这一点
<Button
android:layout_below="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:text="ON"
android:onClick="switchOn"/>
<Button
android:layout_toRightOf="@+id/b1"
android:layout_below="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b2"
android:text="OFF"
android:onClick="switchOff"/>
public void Connect(View view){
String url="http://192.168.1.3/index.php";
DefaultHttpClient client=new DefaultHttpClient();
HttpGet get=new HttpGet(url);
try
{
HttpResponse response=client.execute(get);
HttpEntity entity=response.getEntity();
String result= EntityUtils.toString(entity);
}
catch(Exception ex)
{
Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();
}
}