how do i send my location via url in sms?

我们两清 提交于 2019-12-04 21:08:14
Shree Krishna

I suggest you to get the current latitude and longitude of the device. The in step two you can create a String which is a searching url with those parameters which looks like this

   String message = "http://maps.google.com/?q=" + {latitude} + "," + {longitude}

And for the further info to get the current longitude and latitude have a look here

normal way then you can insert a url as bellow:

String pos_url = "http://sharegps.com?lat=00000000000&long=00000000000"; // you can replace your real gps position and your domain (or use maps.google.com)

First way:

SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(ph, null, pos_url, null, null);
        Toast.makeText(getApplicationContext(), "SMS SENT",
                Toast.LENGTH_LONG).show();

Second way:

private void shareTextUrl() {
    Intent share = new Intent(android.content.Intent.ACTION_SEND);
    share.setType("text/plain");
    share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

    // Add data to the intent, the receiving app will decide
    // what to do with it.
    share.putExtra(Intent.EXTRA_SUBJECT, "Title Of The Post");

    share.putExtra(Intent.EXTRA_TEXT, pos_url);

    startActivity(Intent.createChooser(share, "Share location!"));

}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!