-1
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i(TAG, "INSIDE onCreate");
//ACCESSING LOCATION MANAGER
String svcName=Context.LOCATION_SERVICE;
locationmanager=(LocationManager)getSystemService(svcName);
//SPECIFY THE CRITERIA
criteria.setAccuracy(Criteria.ACCURACY_MEDIUM);
criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setSpeedRequired(false);
criteria.setCostAllowed(false);
//get the list of providers
provider=locationmanager.getBestProvider(criteria, true);
if(provider==null)
{
Log.i(TAG, "inside enable gps");
final boolean enablegps = locationmanager.isProviderEnabled(LocationManager.GPS_PROVIDER);
//show dialog box and enable gps..
if(!enablegps)
{
Log.i(TAG, "dialog box");
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Wmi2Activity.this);
// set title
alertDialogBuilder.setTitle("Is GPS Enable??");
// set dialog message
alertDialogBuilder
.setMessage("Click yes to exit!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog,final int id) {
//gotoEnablrGPS();
dialog.cancel();
}
});
alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog,final int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
}
else{
mylocation.setText("no location provider available");
}
}
您是否收到任何錯誤/異常?您是否添加了gps權限?代碼聖牆,蝙蝠俠! – 2012-07-17 05:33:49
聖牆代碼,蝙蝠俠!你的問題到底是什麼? – gobernador 2012-07-17 05:34:01
而不是AlertDialog alertDialog = alertDialogBuilder.create(); 只寫alertDialogBuilder.create(); – AkashG 2012-07-17 05:35:34