2016-09-28 12 views
2

これは私のコードです。 (それは、設定を移動するalertdialogを作る) しかし、私はGPSを有効にしたいときは、 "GPSを有効にする"ボタンをクリックします。 アンドロイドは、一度実行するだけでなく、アプリを実行するとボタンクリックを有効にしますか?ボタンをクリックするとアンドロイドGPSが有効になります

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setMessage("Your GPS is disabled! Would you like to enable it?") 
.setCancelable(false) 
.setPositiveButton("Enable GPS", 
new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int id) { 
     moveConfigGPS(); 
    } 
}).setNegativeButton("Do nothing", 
new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int id) { 
     dialog.cancel(); 
    } 
}); 

AlertDialog alert = builder.create(); 
alert.show(); 

答えて

0

は、私はあなたがGoogleのようなワンクリックでGPS位置をオンにしたいと思いますか。

enter image description here

startResolutionForResult(活動、int)を呼び出して、場所の設定を変更する権限をユーザーに促すように。このメソッドは、場所の設定を変更するためのユーザーの権限を求めるダイアログを表示します。 This link shows how to check the location settings, and how to call startResolutionForResult(Activity, int).

1

あなただけのGPSを有効にすることはできません、することができます。この目的でのみオープンGPSの設定:

Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
startActivity(intent); 
0
User these method to on GPS : 

    intent1 = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
    startActivity(intent1); 

and add these method to check GPS is on or Off ?? 
public void CheckGpsStatus(){ 

locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE); 

GpsStatus = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 

if(GpsStatus == true) 
{ 
textview.setText("Location Services Is Enabled"); 
}else { 
textview.setText("Location Services Is Disabled"); 
} 

} 
関連する問題