私は初心者の開発者です。Android GPS 追跡アプリを作成しています。緯度と経度を収集するように作成しました。電話番号と IMEI を電話画面に表示することもできます。私の質問は、どのように送信すればよいかです。これらのデータをサーバーに送信して、Google マップでユーザーを追跡できるようにする必要があります。これが私の最初の質問です。私のニーズを理解していただければ幸いです。
(これは以下の私のコードです。投稿データを追加してみてください。動作しません)
package com.exemple.travelinsave;
@SuppressWarnings("unused")
public class PrincipalActivity extends Activity {
TextView Textlat; //= (TextView) findViewById(R.id.textlat);
TextView Textlong; //= (TextView) findViewById(R.id.textlong);
TextView EditNum; //= (TextView) findViewById(R.id.textlat);
TextView EditIMEI; //= (TextView) findViewById(R.id.textlong);
private final String TAG = "DemoButtonApp";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);
Textlat = (TextView)findViewById(R.id.Textlat);
Textlong = (TextView)findViewById(R.id.Textlong);
EditNum = (TextView)findViewById(R.id.EditNum);
EditIMEI = (TextView)findViewById(R.id.EditIMEI);
TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String IMEINum = manager.getDeviceId();
String phonenum = manager.getLine1Number();
EditIMEI.setText(IMEINum);
EditNum.setText(phonenum);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new mylocationlistener ();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
SetupsendButton();
}
class mylocationlistener implements LocationListener{
@Override
public void onLocationChanged(Location location) {
if(location !=null)
{
double pLat = location.getLatitude();
double pLong = location.getLongitude();
Textlat.setText(Double.toString(pLat));
Textlong.setText(Double.toString(pLong));
}
}
}
private void SetupsendButton() {
// TODO Auto-generated method stub
Button SendButton = (Button) findViewById(R.id.sendButton);
SendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Log.i(TAG, "You clicked the bottuon!");
//Toast.makeText(PrincipalActivity.this, "You Clicked it ", Toast.LENGTH_LONG).show();
try {
HttpClient client = new DefaultHttpClient();
String postURL = "http://cybergracz.com/wp-includes/post.php";
HttpPost post = new HttpPost(postURL);
List<NameValuePair> params = new ArrayList<NameValuePair>(4);
Textlat = (TextView)findViewById(R.id.Textlat);
Textlong = (TextView)findViewById(R.id.Textlong);
EditNum = (TextView)findViewById(R.id.EditNum);
EditIMEI = (TextView)findViewById(R.id.EditIMEI);
params.add(new BasicNameValuePair("PhoneNUM", String.valueOf(EditNum.getText())));
params.add(new BasicNameValuePair("Latitude ", String.valueOf(Textlat.getText())));
params.add(new BasicNameValuePair("Longitude", String.valueOf(Textlong.getText())));
params.add(new BasicNameValuePair("DeviceID", String.valueOf(EditIMEI.getText())));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
if (resEntity != null) {
Log.i("RESPONSE",EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
}
try {
HttpClient client = new DefaultHttpClient();
Textlat = (TextView)findViewById(R.id.Textlat);
Textlong = (TextView)findViewById(R.id.Textlong);
EditNum = (TextView)findViewById(R.id.EditNum);
EditIMEI = (TextView)findViewById(R.id.EditIMEI);
String PostDatS = "EditNum=" + EditNum;
PostDatS = PostDatS + "EditIMEI=" + EditIMEI;
PostDatS = PostDatS + "Textlat=" + Textlat;
PostDatS = PostDatS + "Textlong=" + Textlong;
String postURL = "http://starcitydirt.com/get.php?" + PostDatS;
HttpPost post = new HttpPost(postURL);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("user", "kris"));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
if (resEntity != null) {
Log.i("RESPONSE",EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.principal, menu);
return true;
}
}