2012-04-11 80 views
1

我是一个android newbi。我对一个非常原始的问题表示歉意。 我打算开发一个短信消息的android应用程序,以便当接收者收到消息时,发件人的物理位置也自动显示(使用发件人的GPS)可能是Lat Long格式。 我的问题是,如何去解决这个问题? 提前致谢。android短信应用程序显示发件人的位置

回答

0

我想..让发送者的位置,完全依赖于sender..ie如果发件人决定说出他的位置..只有收件人能够得到他的位置..所以..申请你想使应在发送者的手机......在这种情况下..

创建文本框和一个按钮的活动来发送消息,这样的..

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); 
} 
}); 

} 
+0

非常感谢。我mona给它一个镜头 – 2012-04-12 03:32:53

+0

... PLZ你会解释“新的MyLocationListener()”它不是在代码中? – 2012-04-20 08:38:20

+0

你需要一个位置监听器,当你想更新..但我们不希望任何更新..只想当前位置..所以没有必要LocationListener的 – 5hssba 2012-04-21 05:29:28

0
if (ActivityCompat.checkSelfPermission(**this**, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && 
         ActivityCompat.checkSelfPermission(**this**, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) 
{ 
} 

如何解决的第一个参数错误,即“这个“?

相关问题