Question

what i am trying to do is to send my current location map as url via sms so user can open my location once he open the url that have been added to the sms but what i keep seeing when i try to send the message is the url but it appears as regular text not AS URL !!

here is my code please tell me what i am doing wrong :

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();
                }


            }


        }
Was it helpful?

Solution

Use

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "http://maps.google.com/?q="+lat+","+lng, null, null);

this may help you

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top