有没有办法以编程方式停用Google位置服务? 我想用一个小部件编写一个应用程序来关闭它。
感谢您的帮助!
答案 0 :(得分:3)
有没有办法以编程方式停用Google位置服务?
不,抱歉,您无法以编程方式禁用GPS等,除非通过系统分区上安装的应用程序或通过固件的签名密钥签名。 IOW,你需要一部扎根电话。
答案 1 :(得分:1)
据我所知,LocationManager是一个无法关闭的系统服务。但是,您可以禁用该服务使用的所有位置提供程序,例如无线位置,GPS等。
答案 2 :(得分:0)
简短的回答是,不。但如果你真的需要关闭它,你可以提示用户这样做:
LocationManager loc = (LocationManager) this.getSystemService( Context.LOCATION_SERVICE );
if( loc.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER ) )
{
Toast.makeText( this, "Please turn off GPS", Toast.LENGTH_LONG).show();
Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS );
startActivity(myIntent);
}
else
{
// Do nothing
}
这可能对您的情况没有帮助,但是我知道更改设置的唯一方法。
答案 3 :(得分:0)
如果您使用的是UiAutomater
,则可以通过模拟快速设置中位置选项的点击来关闭位置服务。过滤器逻辑可以是平台相关的。您可以使用uiautomatorviewer
分析视图层次结构。
即
UiDevice.getInstance(getInstrumentation()).openQuickSettings();
UiDevice.getInstance(getInstrumentation()).findObject(new UiSelector().descriptionContains("Location").className(ViewGroup.class)).click();
<强>的build.gradle 强>
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'