我刚开始使用Google地图,我试图在GPS关闭时显示一个对话框。 这是我的onProviderDisabled方法的代码。onProviderDisabled对话框未显示
@Override
public void onProviderDisabled(String provider) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("GPS is disabled");
builder.setC
ancelable(false);
builder.setPositiveButton("Enable GPS", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Intent startGPS = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(startGPS);
}
});
builder.setNegativeButton("Leave GPS off", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
我也已将此添加到OnCreate中...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapSettings();
LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
String provider = lm.getBestProvider(new Criteria(), true);
if(provider == null)
{
onProviderDisabled(provider);
}
}
感谢您寻找。 :-)