自动通过SMS发送GPS坐标

| 我制作了一个显示我的GPS坐标(经度和纬度)数字的应用程序,该应用程序没有地图。但是,我想在每次打开此应用程序时自动将经纬度和长号发送至手机号码/电话号码(无需发送按钮)。任何人都可以帮助我。 Gps.java
package Sample.gps.send;

import android.app.Activity;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;

public class Gps extends Activity
{
@Override

public void onCreate(Bundle savedInstanceState)
{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);


/* Use the LocationManager class to obtain GPS locations */

LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

LocationListener mlocListener = new MyLocationListener();


mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);


}


/* Class My Location Listener */

public class MyLocationListener implements LocationListener
{

@Override

public void onLocationChanged(Location loc)

{

loc.getLatitude();

loc.getLongitude();
String Text = \"My location is: \" +

\"Latitude = \" + loc.getLatitude() +

\"Longitude = \" + loc.getLongitude();




Toast.makeText( getApplicationContext(),Text,Toast.LENGTH_SHORT).show();

}


@Override

public void onProviderDisabled(String provider)

{

Toast.makeText( getApplicationContext(),
\"GPS Disabled\",


Toast.LENGTH_SHORT ).show();

}


@Override

public void onProviderEnabled(String provider)

{

Toast.makeText( getApplicationContext(),


\"GPS Enabled\",
Toast.LENGTH_SHORT).show();

}


@Override

public void onStatusChanged(String provider, int status, Bundle extras)

{


}

}

}
这是针对AndroidManifest.xml的
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"
          package=\"Sample.gps.send\"
          android:versionCode=\"1\"
          android:versionName=\"1.0\">

<application android:icon=\"@drawable/icon\" 
             android:label=\"@string/app_name\">
<activity android:name=\".UseGps\"
          android:label=\"@string/app_name\">
<intent-filter>
<action android:name=\"android.intent.action.MAIN\"/>
<category android:name=\"android.intent.category.LAUNCHER\"/>
</intent-filter>          
          </activity>            
             </application> 
<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\">
</uses-permission>          
 <uses-permission android:name=\"android.permission.SEND_SMS\">
    </uses-permission>             
          </manifest>
这里MyLocationListener是一个内部类。任何人都可以告诉每当调用onLocationChanged方法时如何检索坐标吗?使用Toast显示位置。是否可以通过从onCreate()调用任何方法来获取坐标?     
已邀请:
        参见http://mobiforge.com/developing/story/sms-messaging-android。该教程将向您展示如何发送短信,从而使您能够弄清楚您需要做什么。 发布代码示例时请使用代码标签:-)     

要回复问题请先登录注册