@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");
}
}
質問する
409 次
1 に答える
0
コードを次のように変更します。
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Wmi2Activity.this);
に:
alertDialog.show();
このコードに:
new AlertDialog.Builder().setTitle("Is GPS Enable??")
.setMessage("Click yes to exit!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog,final int id) {
//gotoEnablrGPS();
dialog.cancel();
}
}).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().show();
それはうまくいくかもしれません。
于 2012-07-17T10:27:22.993 に答える