Per favore dimmi dove posizionare il codice.Come postare qualsiasi dato usando il metodo POST in Android
sto creando un app per,
- posizione Get,
- Quando la posizione è ottenuto, e il pulsante Invia viene cliccato,
- Rapidamente, inviarlo tramite POST metodo (HTTP) per la mia pagina PHP.
come in seguito App Review, è possibile vedere due box di input con LAT & LUNGHI valori & Nome:
ho il seguente codice per ottenere la posizione:
public class MainActivity extends Activity implements LocationListener {
EditText lat;
EditText lng;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/********** get Gps location service LocationManager object ***********/
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
/* CAL METHOD requestLocationUpdates */
// Parameters :
// First(provider) : the name of the provider with which to register
// Second(minTime) : the minimum time interval for notifications,
// in milliseconds. This field is only used as a hint
// to conserve power, and actual time between location
// updates may be greater or lesser than this value.
// Third(minDistance) : the minimum distance interval for notifications, in meters
// Fourth(listener) : a {#link LocationListener} whose onLocationChanged(Location)
// method will be called for each location update
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
3000, // 3 sec
10, this);
/********* After registration onLocationChanged method ********/
/********* called periodically after each 3 sec ***********/
}
/************* Called after each 3 sec **********/
@Override
public void onLocationChanged(Location location) {
lat = (EditText)findViewById(R.id.lat);
lng = (EditText)findViewById(R.id.lng);
lat.setText(""+location.getLatitude());
lng.setText(""+location.getLongitude());
String str = "Latitude: "+location.getLatitude()+"Longitude: "+location.getLongitude();
Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
}
@Override
public void onProviderDisabled(String provider) {
/******** Called when User off Gps *********/
Toast.makeText(getBaseContext(), "GPS is OFF, Turn it on", Toast.LENGTH_LONG).show();
}
@Override
public void onProviderEnabled(String provider) {
/******** Called when User on Gps *********/
Toast.makeText(getBaseContext(), "GPS ON ", Toast.LENGTH_LONG).show();
Toast.makeText(getBaseContext(), "Waiting for location..... ", Toast.LENGTH_LONG).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Questo era il codice per ottenere la posizione e riempire i valori LAT & LONG su una casella di input, quando il GPS ottiene una correzione.
Ora, ho bisogno del codice per POST ing tutti i dati nel mio PHP pagina.
vedi questo link può essere utile inviare valori dall'applicazione Android alla pagina php https://adilmukarram.wordpress.com/2011/01/29/sending-and-receiving-data-from-a-php- web-application/,,,,,,,,,,,,,,,,,,,,,,https: //anujarosha.wordpress.com/2012/01/27/handling-http-post-method-in- android/ – Hanuman
Prima di tutto dobbiamo sapere cosa accetta l'endpoint PHP: sta ottenendo JSON? Quali attributi si aspetta? Se richiede un token o qualche altra autenticazione, sai già come farlo? Lascia fuori specifiche, come l'URL, ma i dettagli contano per una buona risposta. – Phil
usa queste informazioni lnk per ottenere knwoladge sul metodo Post e sui servizi PHP anche http://www.androidhive.info/2011/10/android-making-http-requests/ –