- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在谷歌地图应用程序中检查 Activity 的互联网连接,并且我想在互联网处于 Activity 状态时执行特定操作,如果互联网处于非 Activity 状态则执行另一个操作。
if(manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
{
getcurrentlocation();
}
else
{
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Internet is mandatory for this application,\n connect and restart the app")
.setCancelable(false)
.setNeutralButton("OK",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = alertDialogBuilder.create();
alert.show();
}
问题在于,即使没有互联网,manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)也会返回true。请帮忙!!
最佳答案
isproviderenabled 返回当前启用的提供程序的字符串。它不提供 Activity 网络连接的状态。检查 this
如果您想检查设备是否有互联网连接,请调用以下函数。检查它的值,如果它为空则警告用户否则做你的事情
public boolean isconnected() {
ConnectivityManager cm =(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
将 if 条件更改为如下
if(isconnected())
getcurrentlocation();
else
//alert user
关于java - 即使没有启用互联网,isProviderEnabled(LocationManager.NETWORK_PROVIDER) 也会返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24838417/
我正在编写用于获取手机当前位置(纬度和经度)的代码。无论电话是否提供网络位置服务,我都会 toast 。这个 toast 永远不会出现。另一个问题是,为了使用 Network_location 获取当
您好,我正在开发小型 Android 应用程序,我试图在其中检查网络提供商是否已启用。如果没有,则寻找 GPS 提供商。但在我的情况下,网络提供商总是返回 true。我尝试按照以下方式进行检查
我有这个代码 lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); boolean isGPS = lm.
我有一个应用程序使用网络提供商来定位。每次应用程序启动时,它都会使用 LocationManager 中的 isProviderEnabled() 方法检查网络提供商是否已启用。 如果它返回 fals
在这种情况下,我使用 GPS 作为提供者,我尝试在建筑物内行走,但它似乎找不到位置。是的,在建筑物中 GPS 不起作用是有道理的。那么,为什么 isProviderEnabled 返回 true?无论
我们已经为 Android 实现了基于地理的应用程序,因此我们需要确保始终启用 GPS。问题是 manager.isProviderEnabled( LocationManager.GPS_PROVI
这个问题在这里已经有了答案: How do I find out if the GPS of an Android device is enabled (11 个答案) 关闭 6 年前。 我无法确定
我可以使用 isProviderEnabled() 检查 GPS 是否打开。如果它没有打开,我将启动 Intent 以便用户可以启用 GPS。最后,我再次检查用户是否启用了 GPS。如果用户不启用 G
我正在使用 NETWORK_PROVIDER 获取地点的 latitude 和 longitude。 我已经检查了“位置和安全”中的设置并启用了“使用无线网络”。但是 "isProviderEnabl
我正在测试一个使用位置服务的应用。每当我的位置服务关闭时,它都会返回 null 导致NPE(空指针异常)。经过一番搜索后我发现 isGPSEnabled = locationManager.i
我不知道为什么,但我的可变 isNetowrkEnabled 总是返回 true。我的设备上是否启用互联网并不重要。 这是我的 GPSTracker 类: public class GPSTracke
我正在谷歌地图应用程序中检查 Activity 的互联网连接,并且我想在互联网处于 Activity 状态时执行特定操作,如果互联网处于非 Activity 状态则执行另一个操作。 if(manage
我的应用程序的一位用户报告说,即使他确实打开了应用程序,它也会告诉网络位置信息已关闭。他给我发了一些屏幕截图,它们让我思考; LocationManager.isProviderEnabled(Loc
我试过了 NETWORK_PROVIDER 获取地点的经纬度。 我的测试设备是 LG Optimus G Pro(LG-F240L) Android 4.4.2,API 19。 使用的是Wi-Fi网络
我是一名优秀的程序员,十分优秀!