RT,代码如下:
package oms.test;
import android.app.Activity;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
public class test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager locationManager;
String contest =Context.LOCATION_SERVICE;
locationManager= (LocationManager)getSystemService(contest);
Location location =locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, locationListener);
}
private final LocationListener locationListener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
updateWithNewLocation(null);
}
@Override
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
};
private void updateWithNewLocation (Location location){
String locationString;
TextView textView;
textView =(TextView)findViewById(R.id.textview1);
if (location!=null){
locationString="lat:"+location.getLatitude()+"\n long:"+location.getLongitude();
}else{
locationString="no data";
}
textView.setText(locationString);
}
}
第一次可以通过ddms发送的经纬度正确监听到,后面几次一点反应都没有,请问这是怎么回事?
相关推荐
6. **DDMS(Dalvik Debug Monitor Service)**:在微信版本变化时,如果内部资源ID发生变化,可以使用DDMS工具查看微信的UI元素及其对应的资源ID,以适应不同版本的微信。 7. **数据解析**:获取到微信消息后,可能...
在Android应用开发中,DDMS(Dalvik Debug Monitor Service)是Android SDK中一个重要的调试工具,它提供了多种功能,如设备管理、进程管理、内存分析、线程跟踪以及UI界面的截图等。本资料包“Android应用源码之6....
7. **模拟地理位置**:在测试定位服务相关功能时,可以模拟设备的位置变化。 8. **模拟电话事件**:如拨打电话、发送短信,用于测试通话和消息处理功能。 接下来,我们转向Button控件。在Android用户界面设计中,...
3. **在地图上标记位置**:有了位置信息后,我们可以创建一个Marker对象,设置其位置为当前的经纬度,然后添加到MapView中。Marker会显示在地图上的特定位置,代表设备的当前位置。 4. **实时更新**:为了实现位置...
- **动态监听位置变化**:通过`requestLocationUpdates()`方法注册一个LocationListener,以便在位置发生变化时接收到通知。例如,每2秒更新一次,如果位置变化超过10米: ```java locationManager....
在Android平台上,实现“实时读取微信最新消息”的功能涉及到多个技术层面,主要涵盖Android系统权限、微信API接口(如果存在)、系统消息监听以及数据解析等。以下将详细阐述这个主题涉及的关键知识点。 首先,要...
因此,应用必须适配这一变化,确保在需要时请求权限。 2. 能耗优化:GPS使用大量电量,频繁开启会影响电池寿命。因此,应合理设定定位频率和精度,必要时使用低功耗模式。 3. 定位精度:不同的定位提供者有不同的...