只有在Android中至少启用了一个位置验证器时才允许输入应用程序
问题描述:
在我的应用程序中,用户必须至少启用一个位置提供程序。为了知道如果启用我用:只有在Android中至少启用了一个位置验证器时才允许输入应用程序
isGpsLocationEnabled = ((LocationManager) getSystemService(LOCATION_SERVICE))
.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkLocationEnabled = ((LocationManager) getSystemService(LOCATION_SERVICE))
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
现在,我创建了一个活动:提醒没有被启用,如果用户选择“启用GPS”我打开与ACTION_LOCATION_SOURCE_SETTINGS意图GPS选项。
我想(选择用户后)检查他是否启用了一个,并且只有让他继续,如果他这样做。
我有按钮,在“启用GPS”
showGpsOptions();
isGpsLocationEnabled = ((LocationManager) getSystemService(LOCATION_SERVICE))
.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkLocationEnabled = ((LocationManager) getSystemService(LOCATION_SERVICE))
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (isGpsLocationEnabled || isNetworkLocationEnabled){
Intent startIntent = new Intent(EnableLocationProviderActivity.this, SensingService.class);
startService(startIntent);
} else {
finish();
}
我的问题是isGpsLocationEnabled和isNetworkLocationEnabled永远不会与在网络设置中用户选择的代码继续showGpsOptions后,其执行更新的代码() (我知道它不能阻止UI线程,但我怎么能超越这种情况)?
有没有办法在用户选择网络设置中的某些内容后执行代码?
谢谢!吉列尔莫。
答
时设置屏幕进来你activity
,逻辑上的前部和ACC到文档,你activity
是paused
,然后在需要时您activity
是resumed
......所以我想,你应该使用检查代码中onResume
...
您可以随时在后台运行一个线程(接收器,服务,线程),它将检查情况并运行代码。 – MKJParekh 2012-02-29 05:27:30