在android studio kotlin中以短信形式发送当前位置

时间:2019-05-12 18:34:59

标签: android kotlin

我想以短信的形式发送当前位置。如何获得此位置并在Kotlin中作为消息发送?

emergency = (Button) findViewById(R.id.emergency);

emergency.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v){
        GPStracker g = new GPStracker(getApplicationContext());
        Location l = g.getLocation();
        if (l != null){
            double lat = l.getLatitude();
            double lon = l.getLongitude();
            String message="http://maps.google.com/maps?saddr="+lat+","+lon;
            String number = "xxxxxxxx";
            SmsManager smsManager = SmsManager.getDefault();
            StringBuffer smsBody = new StringBuffer();
            smsBody.append(Uri.parse(message));
            android.telephony.SmsManager.getDefault().sendTextMessage(number, null, smsBody.toString(), null,null);
        }
    }
});

0 个答案:

没有答案