2016-03-08 103 views
-1

我正在做一个android项目,所以任何人都可以告诉我如何通过短信在URL中发送我的当前位置。 让我解释什么我想知道什么时候移动手机抖动然后我的应用程序发送一个字符串的SMS到选定的联系人现在我想添加位置功能在我的应用程序意味着我想通过URL在SMS中发送位置,当接收器点击网址,然后他可以在他的地图发件人的位置?如何通过短信网址发送我的位置?

private void sendSMS(String ph, String message) { 
     SmsManager smsManager = SmsManager.getDefault(); 
     smsManager.sendTextMessage(ph, null, message, null, null); 
     Toast.makeText(getApplicationContext(), "SMS SENT", 
       Toast.LENGTH_LONG).show(); 
    } 

回答

1

我建议你来获得当前latitude和设备的longitude。在第二步中,您可以创建一个字符串,它是一个与它看起来像这样

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

这些参数,为进一步的信息搜索url来获得当前longitudelatitude看看here

+0

我可以与此SmsManager smsManager = SmsManager.getDefault完成(); smsManager.sendTextMessage(“phoneNo”,null,“http://maps.google.com/?q="+lat+","+lng,null,null); – Abhishek

+0

是的,当然,但我没有尝试获得目前的经纬度。你可以自己尝试。 –

+0

@Abhishek最好创建一个变量,而不是在那里写这行。根据我的回答制作一个变量,然后在代码模板中添加该字符串。 –

1

正常方式那么你可以插入一个链接波纹管:

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) 

第一种方式:

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

方式二:

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!")); 

}

+0

字符串pos_url,我应该用onCreate吗? – Abhishek

+0

@Abhishek是的。你可以声明它,并使用任何你想要的地方,但你必须分配值之前,你发送短信 – GiapLee

+0

我做了,但它没有显示发件人的位置 – Abhishek