我想要做的是通过短信将我当前的位置地图作为 url 发送,这样用户一旦打开已添加到短信中的 url 就可以打开我的位置,但是当我尝试发送消息时我一直看到的是 url但它显示为常规文本而不是作为 URL !
这是我的代码,请告诉我我做错了什么:
public class MapLocation extends FragmentActivity {
TextView text;
// Google Map
private GoogleMap googleMap;
String smslocation=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_location);
text=(TextView)findViewById(R.id.textView1);
Button startBtn = (Button) findViewById(R.id.click);
initilizeMap();
startBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
sendSMS();
}
});
}
protected void sendSMS() {
Log.i("Send SMS", "");
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("smsto:"));
smsIntent.setType("vnd.android-dir/mms-sms");
// smsIntent.putExtra("address" , new String ("0123456789"));
smsIntent.putExtra("sms_body" , "i am currently in "+smslocation);
try {
startActivity(smsIntent);
finish();
Log.i("Finished sending SMS...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MapLocation.this,
"SMS faild, please try again later.", Toast.LENGTH_SHORT).show();
}
}
// try {
// // Loading map
// }
//
// @Override
// protected void onResume() {
// super.onResume();
// initilizeMap();
// }
/**
* function to load map If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap !=null) {
setUpMap();
}
}
}
private void setUpMap() {
//enable my location
googleMap.setMyLocationEnabled(true);
//get location object
LocationManager locationManager=(LocationManager)getSystemService(LOCATION_SERVICE);
//to retrive provider
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
//get current location
Location mylocation=locationManager.getLastKnownLocation(provider);
//set map type
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
double latitude = mylocation.getLatitude();
double longitude = mylocation.getLongitude();
LatLng latlng=new LatLng(latitude,longitude);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latlng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(20));
googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude,longitude))).setTitle("you are here!");
Toast.makeText(MapLocation.this, latitude+" "+longitude, Toast.LENGTH_LONG).show();
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
try {
addresses = geocoder.getFromLocation(latitude, longitude, 1);
String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(1);
String country = addresses.get(0).getAddressLine(2);
String cities=addresses.get(0).getAdminArea();
Log.e("address",addresses+"");
Log.e("address",address+"");
Log.e("city",cities+"");
Log.e("country",city+"");
text.setText("your current location is: "+city+""+","+cities+""+","+address+"");
String uri = "http://maps.google.com/maps?saddr=" + mylocation.getLatitude()+","+mylocation.getLongitude();
Uri path= Uri.parse(uri);
smslocation=city+""+","+cities+""+","+address+" "+"check my location at "+path;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}