简体   繁体   English

Android计时器处理程序Java

[英]android timer handler java

I want to insert values in my data base using timer i started with using the timer to display a msg and it work but when i added the call of th function that insert values just the msg display and no data inserted!! 我想使用计时器在我的数据库中插入值,我从使用计时器开始显示味精开始,它可以工作,但是当我添加了第一个插入值的函数时,只显示味精显示而没有插入数据! here is my code 这是我的代码

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());
            }       
            }
}

The solution was to add internet permissions to his manifest. 解决方案是在清单中添加Internet权限。 It's always the simple things. 总是简单的事情。

Please read this link for information on permissions. 请阅读链接以获取有关权限的信息。

The correct format would be: 正确的格式为:

<uses-permission
        android:name="android.permission.INTERNET" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM