如何将GPS状态放在文本框中
How to put GPS status in text box
基本上,如果 GPS 在文本框下方打开并显示 'Enabled',如果关闭,则将文本放入文本框 'Disabled'。
这跟Android开发没什么关系,基本上是简单的思路,但是在Android里面会是这样的(假设你还有其他部分):
textView.setText(isGpsTurnedOn ? "Enabled" : "Disabled");
如果您对获取 GPS 状态感兴趣,请查看 this 问题。
请找到这段代码,希望对您有所帮助
PackageManager pm = getApplicationContext().getPackageManager();
boolean hasGps = pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
if(hasGps){
LocationManager locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
//set enable into TextView here
}else{
//set Disable into TextView here
}
}else{
//set Toast for GPS not available into your device
}
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
textbox_name.setText("Enable");
}
else
textbox_name.setText("Disabled");
试试这个对你有帮助。
基本上,如果 GPS 在文本框下方打开并显示 'Enabled',如果关闭,则将文本放入文本框 'Disabled'。
这跟Android开发没什么关系,基本上是简单的思路,但是在Android里面会是这样的(假设你还有其他部分):
textView.setText(isGpsTurnedOn ? "Enabled" : "Disabled");
如果您对获取 GPS 状态感兴趣,请查看 this 问题。
请找到这段代码,希望对您有所帮助
PackageManager pm = getApplicationContext().getPackageManager();
boolean hasGps = pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
if(hasGps){
LocationManager locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
//set enable into TextView here
}else{
//set Disable into TextView here
}
}else{
//set Toast for GPS not available into your device
}
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
textbox_name.setText("Enable");
}
else
textbox_name.setText("Disabled");
试试这个对你有帮助。