私はビーコンデバイスを検索しようとしています。マホイ&マイナーを取得してからデータを送信しますが、問題が発生しました。私は2つのパート間でデータを送信する方法がわかりません..私はありがとうjsonObject.put("uuid", a)
2つのクラス間でデータを配信する
にbeacon.getMajor()
を入れたい
に!
ここに私のコードです。
try
{
jsonObject.put("value",chatMessage.getDate());
}
catch (JSONException e)
{
e.printStackTrace();
}
jsonobject.put("key",value);
のようにあなたがint value,string value,boolean
値またはものは何でもあなたを割り当てることができます。あなたはすなわち副行うことができますJSONに入れてオブジェクトまたは何かしたい場合はこの場合
private List<String> placesNearBeacon(Beacon beacon) {
int a = beacon.getMajor();
final String b = String.valueOf(beacon.getMajor());
Log.v("show", String.valueOf(a));
Intent intent = new Intent(this,AsyncLogin.class);
intent.putExtra("MAJOR",a);
startActivity(intent);
if (a == 258){
new AsyncLogin().execute(String.valueOf(a));
}
String beaconKey = String.format("%d:%d", beacon.getMajor(), beacon.getMinor());
return Collections.emptyList();
}
enter code here
private class AsyncLogin extends AsyncTask<String, String, String>
{
HttpURLConnection conn;
URL url = null;
Uri a = new Intent().getData();
@Override
protected String doInBackground(String... params) {
try {
// Enter URL address where your php file resides
url = new URL("http://etriplay.com/app/beacon_GetInform.php");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "exception";
}
try {
// Setup HttpURLConnection class to send and receive data from php and mysql
conn = (HttpURLConnection)url.openConnection();
conn.setReadTimeout(READ_TIMEOUT);
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setRequestMethod("POST");
// setDoInput and setDoOutput method depict handling of both send and receive
conn.setDoInput(true);
conn.setDoOutput(true);
// JSON
JSONObject jsonObject = new JSONObject();
jsonObject.put("userid", "membe00001");
jsonObject.put("mail", "[email protected]");
jsonObject.put("uuid", a);
Log.v("v", String.valueOf(jsonObject));
// Open connection for sending data
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(String.valueOf(jsonObject));
writer.flush();
writer.close();
os.close();
conn.connect();