使用 SMS 管理器发送预先保存的消息(字符串形式)



我是Android开发的新手,我经常被卡住。在我的应用程序中,我正在尝试向用户指定的号码发送预先保存的消息。我能够使用 smsmanager 发送消息(基本教程有很大帮助),但我希望程序发送用户已预先定义 GPS 位置信息的消息。

我在 Strings.xml 文件中创建了一个字符串,但我无法从我创建的片段中访问该字符串。所以基本上我怎样才能将预先写好的消息+ GPS信息发送到预先选择的号码?(号码和消息将由用户选择以备将来使用)

String stringineed =getString(R.string.nameofstringyourneedinstringsxml);
double latitude = location.getLatitude();
double longitude = location.getLongitude();
Geocoder gCoder = new Geocoder(context);
List<Address> addresses = null;
try {addresses = gCoder.getFromLocation(latitude, longitude, 1);
    } catch (IOException e) {
    e.printStackTrace();
    }
if (addresses != null && addresses.size() > 0) {
String addressinfo = "addresses.get(0).getAddressLine(0) + "n"+ addresses.get(0).getPremises() + "n"+ addresses.get(0).getCountryCode() + "n"+ addresses.get(0).getPostalCode() + "n""}
String prewrittenmessage =("This is the prewrittenmessage"+addressinfo);
//or stringinneed+""+ addressinfo
String phone = "some chosen number to be sent to";
Intent sendtoemail = new Intent(Intent.ACTION_SEND);
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phone, null, prewrittenmessage ,null, null); 

最新更新