Disable Bluetooth on exit if it was disabled before start (fixes #15).
This commit is contained in:
parent
6a8a7971f8
commit
3fb6c009ba
2 changed files with 14 additions and 0 deletions
|
@ -4,6 +4,7 @@ import android.app.Activity
|
|||
import android.bluetooth.BluetoothAdapter
|
||||
import android.content._
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import com.nutomic.ensichat.R
|
||||
|
@ -24,6 +25,8 @@ object MainActivity {
|
|||
|
||||
val ExtraAddress = "address"
|
||||
|
||||
val PrefWasBluetoothEnabled = "was_bluetooth_enabled"
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,6 +49,12 @@ class MainActivity extends EnsichatActivity {
|
|||
|
||||
if (getIntent.getAction == MainActivity.ActionRequestBluetooth &&
|
||||
Option(BluetoothAdapter.getDefaultAdapter).isDefined) {
|
||||
val btAdapter = BluetoothAdapter.getDefaultAdapter
|
||||
PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.edit()
|
||||
.putBoolean(MainActivity.PrefWasBluetoothEnabled, btAdapter.isEnabled)
|
||||
.apply()
|
||||
|
||||
val intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE)
|
||||
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0)
|
||||
startActivityForResult(intent, RequestSetDiscoverable)
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.nutomic.ensichat.fragments
|
|||
import java.io.File
|
||||
|
||||
import android.app.ListFragment
|
||||
import android.bluetooth.BluetoothAdapter
|
||||
import android.content.{BroadcastReceiver, Context, Intent, IntentFilter}
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
|
@ -111,6 +112,10 @@ class ContactsFragment extends ListFragment with OnClickListener {
|
|||
startActivity(new Intent(getActivity, classOf[SettingsActivity]))
|
||||
true
|
||||
case R.id.exit =>
|
||||
val pm = PreferenceManager.getDefaultSharedPreferences(getActivity)
|
||||
if (!pm.getBoolean(MainActivity.PrefWasBluetoothEnabled, false))
|
||||
BluetoothAdapter.getDefaultAdapter.disable()
|
||||
|
||||
getActivity.stopService(new Intent(getActivity, classOf[ChatService]))
|
||||
getActivity.finish()
|
||||
true
|
||||
|
|
Reference in a new issue