Android 常见操作


android模拟器使用gps定位

在模拟器上获取GPS信息时,使用Location loc = LocationManager.getLastKnownLocation("gps");来获取location信息,但是往往在调试中loc是null的,因为首先需要在模拟器中手动添加GPS信息,有两种手动添加方法

1、在eclipse下,windows-->open perspective-->DDMS-->Emulator control-->Manual下手动设置经纬度,并按send按钮。

2、在cmd下手动添加信息。

(1)首先打开模拟器,然后运行cmd,输入telnet localhost 5554(注:5554是模拟器在本机的端口,有可能不一样哈,具体端口号,模拟器左上方有显示的),这样会出现 Android Console: type 'help' for a list of commands OK的字样。

如果是使用WIN7的朋友,控制台可能会提示telnet无效什么的,那是因为WIN7下默认是不出现telnet的,需要手动打开。具体为:

[1]控制面板-->程序-->打开或关闭Windows功能,然后将Telnet服务器和Telnet客户端勾选上。

[2]然后在管理工具-->服务中手动启动Telnet

(2)使用geo命令模拟发送GPS信号:

geo fix 经度 纬度

(3)这时就会发现在模拟器的状态栏上多了一个GPS的标志~再使用Location loc = LocationManager.getLastKnownLocation("gps");就能获取到该坐标的位置了~~

在Button控件上显示倒计时

public class CountdownTimerActivity extends Activity {
private TimeCount time;
private Button checking;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
time = new TimeCount(60000, 1000);//构造CountDownTimer对象
checking = (Button) findViewById(R.id.button1);
checking.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
time.start();//开始计时
}
});
}

class TimeCount extends CountDownTimer {
public TimeCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);//参数依次为总时长,和计时的时间间隔
}
@Override
public void onFinish() {//计时完毕时触发
checking.setText("重新验证");
checking.setClickable(true);
}
@Override
public void onTick(long millisUntilFinished){//计时过程显示
checking.setClickable(false);
checking.setText(millisUntilFinished /1000+"秒");
}
}
Joyce /
Published under (CC) BY-NC-SA in categories android  tagged with gps  button