2016-03-25 24 views
1

Bu Android uygulaması Android Studio'yu kullanıyor. Fonksiyon, işaret/eddystone'dan verileri taramak ve görüntülemek içindir. Uygulama zaten çalışıyor ve tarama durduktan sonra, veri yerel dosyaya kaydediyor. Ama benim sorunum, tarama verilerini sunucuya aktarmam gerektiğinde, arka uç sunucusuna girmem gerekiyor. Ama acemi olduğum için en iyi yolun ne olduğunu gerçekten bilmiyordum. İşte Android studio'dan sunucuya android uygulamaları kullanarak veri gönderme

veri yerel verilere transfer edecek koddur:

private void stopScanning(Button scanButton) { 
    try { 
     beaconManager.stopRangingBeaconsInRegion(region); 
    } catch (RemoteException e) { 
      // TODO - OK, what now then? 
    } 
    String scanData = logString.toString(); 
    if (scanData.length() > 0) 
    { 
     // Write file 
     fileHelper.createFile(scanData); 
     // Display file created message. 
     Toast.makeText(getBaseContext(), 
       "File saved to:" + getFilesDir().getAbsolutePath(), 
       Toast.LENGTH_SHORT).show(); 
     scanButton.setText(MODE_STOPPED); 
    } else { 
     // We didn't get any data, so there's no point writing an empty file. 
     Toast.makeText(getBaseContext(), 
       "No data captured during scan, output file will not be created.", 
       Toast.LENGTH_SHORT).show(); 
     scanButton.setText(MODE_STOPPED); 
    } 
} 
+0

Sunucuya veri aktarmak, sunucuya veri göndermek veya sunucudan veri almak için http://developer.android.com/intl/zh adresindeki volley veya güçlendirici kitaplığı kullanın. Http://inthecheesefactory.com/blog/retrofit-2.0/en http://developer.android.com/intl/zh -cn/eğitim/voleybol/index.html – Arshad

+0

Güçlendirme çalışmasını öneririm (ayrıca rxandroid ama bu isteğe bağlıdır) http://square.github.io/retrofit/ – hehe

+0

Sunucudaki verileri nasıl almak istersiniz? JSON, XML, sorgu parametreleri olarak, dosyayı yüklemek? – leonziyo

cevap

1

birçok yolu vardır bir sunucuya veri göndermek için, ANCAK ben daha kolay

daha hızlı, çünkü ek Volley Kütüphane kullanmak PREFER ve

Sen Örneğin, alma ve veri göndermek için voleybolu kullanabilirsiniz:, Bu yararlı olduğunu umuyoruz

//Request serever for JsonObject 
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, new Response.Listener<JSONObject>() { 
     @Override 
     public void onResponse(JSONObject response) { 

      //Your code to proceed with fetched data 

      } 
    }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 

     } 
    }){ 
       //This is the method used to put params into the body, this what you will have to use for sending post data 
     @Override 
     public Map<String, String> getParams() throws AuthFailureError { 
      HashMap<String, String> params = new HashMap<String, String>(); 

       params.put("name","jois"); 
      return params; 
     } 

    }; 

    Volley.newRequestQueue(getApplicationContext()).add(request); 




compile 'com.mcxiaoke.volley:library:1.0.19' This is the dependice you will have to add in build.gradle file to use volley library 

ThankYou

+0

Veri göndermek için voleybol kullanıyorum, bir web servisine mi ihtiyacım vardı? ya da doğrudan url sunucusuna gönderebilir miyim? – najihah93

+0

URL ile gönderebilir veya web servisini kullanabilirsiniz! U taksi ikisi de – Jois

İlgili konular