Make Bluetooth an optional requirement.

This commit is contained in:
Felix Ableitner 2015-12-04 00:48:54 +01:00
parent 199b185861
commit b21cf17cea
4 changed files with 10 additions and 7 deletions

View File

@ -10,7 +10,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <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 <application
android:name=".App" android:name=".App"

View File

@ -22,7 +22,7 @@
<!-- MainActivity --> <!-- MainActivity -->
<!-- Toast shown if user denies request to enable bluetooth --> <!-- 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 --> <!-- ContactsFragment -->

View File

@ -44,7 +44,8 @@ class MainActivity extends EnsichatActivity {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) 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) val intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE)
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0) intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0)
startActivityForResult(intent, RequestSetDiscoverable) startActivityForResult(intent, RequestSetDiscoverable)
@ -89,8 +90,7 @@ class MainActivity extends EnsichatActivity {
requestCode match { requestCode match {
case RequestSetDiscoverable => case RequestSetDiscoverable =>
if (resultCode == Activity.RESULT_CANCELED) { if (resultCode == Activity.RESULT_CANCELED) {
Toast.makeText(this, R.string.bluetooth_required, Toast.LENGTH_LONG).show() Toast.makeText(this, R.string.toast_bluetooth_denied, Toast.LENGTH_LONG).show()
finish()
} }
} }

View File

@ -3,6 +3,7 @@ package com.nutomic.ensichat.service
import java.io.File import java.io.File
import android.app.Service import android.app.Service
import android.bluetooth.BluetoothAdapter
import android.content.{Context, Intent} import android.content.{Context, Intent}
import android.os.Handler import android.os.Handler
import com.nutomic.ensichat.bluetooth.BluetoothInterface import com.nutomic.ensichat.bluetooth.BluetoothInterface
@ -47,8 +48,10 @@ class ChatService extends Service {
override def onCreate(): Unit = { override def onCreate(): Unit = {
super.onCreate() super.onCreate()
notificationHandler.showPersistentNotification() notificationHandler.showPersistentNotification()
if (Option(BluetoothAdapter.getDefaultAdapter).isDefined) {
connectionHandler.addTransmissionInterface(new BluetoothInterface(this, new Handler(), connectionHandler.addTransmissionInterface(new BluetoothInterface(this, new Handler(),
connectionHandler)) connectionHandler))
}
connectionHandler.start() connectionHandler.start()
} }