我想使用计时器在我的数据库中插入值,我使用计时器开始显示一个msg并且它可以工作但是当我添加了函数的调用时,只插入了msg显示的值并且没有插入数据!这是我的代码
public class TimertestActivity extends Activity {
private double lat;
private double lng;
Handler handler = new Handler();
Runnable runnable = new Runnable() {
public void run() {
afficher();
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
lat = 123456.98;
lng = 321654.78;
runnable.run();
}
public void afficher()
{
Toast.makeText(getBaseContext(),
"lat" +lat+ "lng" +lng,
Toast.LENGTH_SHORT).show();
insertvalues(lat, lng);
handler.postDelayed(runnable, 25000);
}
public void insertvalues(double lat, double lng){
//http post c à d envoi des données
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost("http://www.pizza-paris.com/clic/marwa/test/form.php?lat="+lat+"&lng="+lng);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
Log.i("postData", response.getStatusLine().toString());
}
catch(Exception e)
{
Log.e("log_tag", "Error in http connection "+e.toString());
}
}
}
答案 0 :(得分:1)
解决方案是为其清单添加互联网权限。这总是很简单的事情。
请阅读this链接以获取有关权限的信息。
正确的格式是:
<uses-permission
android:name="android.permission.INTERNET" />