Bluetooth

BluetoothAdapter blAdapter = BluetoothAdapter.getDefaultAdapter();
if (blAdapter == null || !blAdapter.isEnabled()) {
       Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
       startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}

 

GPS

// setup GPS
LocationManager locManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
      // show open gps message
     AlertDialog.Builder builder = new AlertDialog.Builder(this);
     builder.setTitle(R.string.warning);
     builder.setMessage(R.string.no_gps);
     builder.setNegativeButton(getString(R.string.cancel), new
                    android.content.DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
           }
     });
      builder.setPositiveButton(getString(R.string.ok), new
                    android.content.DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
                // jump to setting
                Intent enableGPSIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(enableGPSIntent);
            }
      });
      builder.show();
}

 

arrow
arrow
    全站熱搜

    JohnDX 發表在 痞客邦 留言(0) 人氣()