如果Android设备离线,可以通过编程找到并获取位置纬度和经度坐标值的可能方法是什么?这可能吗?如果是的话可能的方式是什么?我想知道在没有互联网的情况下没有移动网络/ WIFI ???
答案 0 :(得分:1)
试用以下代码,它会为您提供网络提供商的位置
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location==null){
location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
或者浏览此链接
答案 1 :(得分:-2)
如果没有互联网连接,您可以显示一个警告对话框,告诉用户启用互联网/ 使用此代码可以帮助您启用互联网
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("YOU ARE NOT CONNECTED WITH INTERNET")
.setCancelable(false)
.setPositiveButton("ENABLE INTERNET",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
Intent callInternetsettingIntent = new Intent(
android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS);
startActivity(callInternetsettingIntent);
}
});
builder.setNegativeButton("CANCEL",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();