2016-09-05 12 views
0

私は、アンドロイドでプログラム的にGPSをオン/オフすることについての質問が何度も議論されていることを知っています。私は、このリンクで議論されてきた同じ質問があります。Android 6.xでGPSをプログラムで有効または無効にするにはどうすればよいですか?

How can I enable or disable the GPS programmatically on Android?

をしかしアンドロイド6.xのために働く方法は何ですか?

+0

ないが、gpsの有効と無効にするには、このリンクを確認してくださいGPSのランタイム許可を得る必要がある、これは

に動作しますプライバシーの理由。 – CommonsWare

答えて

0
private void buildAlertMessageNoGps() { 
    final AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setMessage(" Your GPS seems to be disabled, do you want to enable it?") 
      .setCancelable(false) 
      .setPositiveButton("ّyes", new DialogInterface.OnClickListener() { 
       public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) { 
        startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); 
       } 
      }) 
      .setNegativeButton("no", new DialogInterface.OnClickListener() { 
       public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) { 
        dialog.cancel(); 
       } 
      }); 
    final AlertDialog alert = builder.create(); 
    alert.show(); 
} 
関連する問題