public static String getCityNameByGps() {
LocationManager lm = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE); // 高精度
criteria.setAltitudeRequired(false); // 不要求海拔信息
criteria.setBearingRequired(false); // 不要求方位信息
criteria.setCostAllowed(true); // 是否允许付费
criteria.setPowerRequirement(Criteria.POWER_LOW); // 低功耗
String provider = lm.getBestProvider(criteria, true); // 获取GPS信息
Location location = lm.getLastKnownLocation(provider); // 通过GPS获取位置
updateToNewLocation(location);
// 设置监听器,自动更新的最小时间为间隔N秒(1秒为1*1000,这样写主要为了方便)或最小位移变化超过N米
LocationListener locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
updateToNewLocation(location);
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
};
// lm.requestLocationUpdates(provider, 3000, 1, locationListener);
return addressString;
}
/**
*
* [功能描述].
*
* @param location
* [参数说明]
* @createTime 2011-10-11 下午03:22:21
*/
public static void updateToNewLocation(Location location) {
// System.out.println("begin updateLocation****");
if (location != null) {
// System.out.println("location is null");
double lat = location.getLatitude();
double lon = location.getLongitude();
// System.out.println("get lattitude from GPS ===>" + lat);
// System.out.println("get Longitude from GPS ===>" + lon);
// GeoPoint gPoint = new GeoPoint((int) lat, (int) lon);
StringBuilder sb = new StringBuilder();
Geocoder gc = new Geocoder(context, Locale.getDefault());
try {
List<Address> addresses = gc.getFromLocation(lat, lon, 1);
if (addresses.size() > 0) {
Address address = addresses.get(0);
// for (int i = 0; i < address.getMaxAddressLineIndex();
// i++) {
sb.append(address.getAddressLine(1)).append("\n");
// sb.append(address.getLocality()).append("\n");
// sb.append(address.getCountryName()).append("\n");
addressString = sb.toString();
// }
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
addressString = "未知地区";
}
}
// System.out.println("end updateLocation****");
}
/**
* 获取GPS状态
*
* @param context
* @return
*/
public static boolean getGPSState() {
LocationManager locationManager = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
// 判断GPS模块是否开启,如果没有则开启
if (!locationManager
.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
return false;
} else {
return true;
}
}
public static void openGPS() {
LocationManager locationManager = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
if (!locationManager
.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
Intent gpsIntent = new Intent();
gpsIntent.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider");
gpsIntent.addCategory("android.intent.category.ALTERNATIVE");
gpsIntent.setData(Uri.parse("custom:3"));
try {
PendingIntent.getBroadcast(context, 0, gpsIntent, 0).send();
} catch (CanceledException e) {
e.printStackTrace();
}
}
}
分享到:
相关推荐
服务器开机自动发送短信到手机! reg add hkcu\software\microsoft\windows\currentversion\run /v feixin /t reg_sz /d c:\windows\feixin.bat /f :: sno 为自己的手机号;psw 为飞信密码 ;msg 为消息 set sno=...
2)当公网IP变化时或定时时间到时自动发送邮件到指定邮箱。3)可以设置发送邮箱账号、接收邮箱账号及密码。SMTP服务器及端口号可设置。支持QQ、163等主流SMTP服务器。4)支持普通SMTP(25端口)及SSL SMTP(465端口...
隐私空间:可以设置保密的联系人,与保密联系人之间的短信与通话记录就会被加密起来。 题外话:在研究开机启动的时候,是在开机启动广播中结束360进程,然后自己创建动态广播,结果,测试时发现安装测试程序后,...
加入开机运行,便可在后台监控电脑 定时截屏上传到指定邮箱
分析短信内容,若包含敏感词则屏蔽,保存垃圾短信到垃圾箱中(设计一个垃圾短信的数据库,除了_id外,还包含手机号和短信内容,垃圾短信的收件时间三个字段)。 ①垃圾箱(垃圾箱表)(读取数据库中的信息,用...
防止手机丢失,开机自启检测sim卡是否为原来那张,不是则想一个号码发送短信.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
3.每次开机程序自动运行,检测到别人如果使用你的手机,自动把他的通话记录,跟gps坐标发送到绑定好的手机号上。 4.知道用你手机人的手机号,最近通话记录,gps坐标后,再自己想办法找到这人吧。 具体代码 1.取sim...
给单片机和GSM模块进行上电即可进行发送短信。
代码实现了一个屏幕截图应用程序,可以定时截取屏幕,并将截图通过电子邮件发送给指定的收件人。以下是代码的主要功能: 通过使用pyautogui库来进行屏幕截图。 使用smtplib库来发送电子邮件,以将截图发送给收件人...
利用电脑程序开机,针对电源键坏的小米手机,流程简单,立刻开机
可以把短信内容保存到指定链接,也可以保存到手机txt文件中 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.xxxxxxxxx.com/xxxx?nr=" + msg.Body.ToString() + "&ld=" + msg.From....
Qualcomm手机平台按下电源键后的完整开机流程图
智能手机发展史及手机开机电路简介
(1) 有开机、关机键、信息发送键、十个数字键、退格键、查询预存电话号码的功能键,以及向前、向后翻页键; (2) 用一个矩形窗口显示拨号数字或预存电话号码; (3) 预存电话号码最多20个,每个号码应有一行汉字...
安卓开发实现开机启动跳转到指定activity
一款很漂亮的开机画面,手机需要ROOT之后用RE文件管理器找到 system/media替换里面的bootanimation.zip(下载后改成这个名字,不能解压)
unity打包安卓实现开机自启。本项目源码需要androidStudio4.1打开, unity使用方法:解压后把"androidAutoStar\app\build\outputs\aar\app-debug.aar"文件导入到unity项目中, 打包成功后安装到手机运行后重启手机,...
可更换手机的开机动画教程在http://www.candou.com/tutorial/skills/2012-08-03/447810.shtml
手机开机原理图讲解,包含基本缩小,开机电路分析,时钟电路,,开机上电时序,充电电路分析,电池供电分析,etc
强制修改开机密码的源码的方式发送到