我是Android的初学者。我开发了一个应用程序,它将位置信息发送到服务器(纬度和经度值)。
我现在使用Dynamic IP
as 来发送信息。
我面临的问题是在使用信息时WIFI
将信息传递到服务器,但是当我使用时,我Mobile Internet
无法将信息发送到服务器。请帮忙。
Location location = locationManager.getLastKnownLocation( LocationManager.NETWORK_PROVIDER);
if (location != null)
{
String message = String.format( "Current Location \n Longitude: %1$s \n Latitude: %2$s ",location.getLongitude(), location.getLatitude());
Toast.makeText(MainActivity.this, message,Toast.LENGTH_LONG).show();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.7/YourPhpScript1.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("message", message));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
}
catch (ClientProtocolException e)
{
}
catch (IOException e)
{
}`
这里 192.168.1.7 是我的动态 IP 地址