Make Bluetooth an optional requirement.
This commit is contained in:
parent
199b185861
commit
b21cf17cea
4 changed files with 10 additions and 7 deletions
|
@ -10,7 +10,7 @@
|
|||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
|
||||
<uses-feature android:name="android.hardware.bluetooth" android:required="true" />
|
||||
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<!-- MainActivity -->
|
||||
|
||||
<!-- Toast shown if user denies request to enable bluetooth -->
|
||||
<string name="bluetooth_required">Bluetooth is required for this app.</string>
|
||||
<string name="toast_bluetooth_denied">Please enable Bluetooth to access the complete app functionality.</string>
|
||||
|
||||
|
||||
<!-- ContactsFragment -->
|
||||
|
|
|
@ -44,7 +44,8 @@ class MainActivity extends EnsichatActivity {
|
|||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
if (getIntent.getAction == MainActivity.ActionRequestBluetooth) {
|
||||
if (getIntent.getAction == MainActivity.ActionRequestBluetooth &&
|
||||
Option(BluetoothAdapter.getDefaultAdapter).isDefined) {
|
||||
val intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE)
|
||||
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0)
|
||||
startActivityForResult(intent, RequestSetDiscoverable)
|
||||
|
@ -89,8 +90,7 @@ class MainActivity extends EnsichatActivity {
|
|||
requestCode match {
|
||||
case RequestSetDiscoverable =>
|
||||
if (resultCode == Activity.RESULT_CANCELED) {
|
||||
Toast.makeText(this, R.string.bluetooth_required, Toast.LENGTH_LONG).show()
|
||||
finish()
|
||||
Toast.makeText(this, R.string.toast_bluetooth_denied, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.nutomic.ensichat.service
|
|||
import java.io.File
|
||||
|
||||
import android.app.Service
|
||||
import android.bluetooth.BluetoothAdapter
|
||||
import android.content.{Context, Intent}
|
||||
import android.os.Handler
|
||||
import com.nutomic.ensichat.bluetooth.BluetoothInterface
|
||||
|
@ -47,8 +48,10 @@ class ChatService extends Service {
|
|||
override def onCreate(): Unit = {
|
||||
super.onCreate()
|
||||
notificationHandler.showPersistentNotification()
|
||||
connectionHandler.addTransmissionInterface(new BluetoothInterface(this, new Handler(),
|
||||
connectionHandler))
|
||||
if (Option(BluetoothAdapter.getDefaultAdapter).isDefined) {
|
||||
connectionHandler.addTransmissionInterface(new BluetoothInterface(this, new Handler(),
|
||||
connectionHandler))
|
||||
}
|
||||
connectionHandler.start()
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue