2016-03-08 105 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