我是一个Android新手。我对一个非常原始的问题表示歉意。 我打算开发一个用于sms消息传递的android应用程序,以便当接收者收到消息时,发送者的物理位置也会自动显示(使用发送者的GPS)可能是Lat Long格式。 我的问题是,如何解决这个问题? 提前致谢。
答案 0 :(得分:0)
我认为..获取发件人的位置完全取决于发件人..如果发件人决定透露他的位置..只有收件人才能获得他的位置..所以..你想要制作的应用程序应该是发件人的电话...在这种情况下..
创建一个带有文本字段的活动和一个按钮来发送这样的消息..
class A extends Activity
{
String s;
Oncreate()
{
editText = (EditText) findViewById(R.id.message);
sendBtn = (Button)findViewById(R.id.send);
sendBtn .setonclickListener(new OnClickListener(){
public void Onclick(){
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener()
);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
clat=location.getLatitude();
clon=location.getLongitude();
}
s=editText.getText().toString()+"lat"+clat+"long"+clong
PendingIntent pi = PendingIntent.getActivity(this, 0,
new Intent(this, Object.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, s, pi, null);
}
});
}
答案 1 :(得分:0)
if (ActivityCompat.checkSelfPermission(**this**, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(**this**, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
{
}
如何解决第一个参数中的错误,即“ this ”?