Changed MainActivity to request bluetooth on start.

If bluetooth is denied, we exit with an error toast.
This commit is contained in:
Felix Ableitner 2014-10-16 23:34:45 +03:00
parent 6579a754a7
commit 63c58a780e
3 changed files with 23 additions and 1 deletions

View file

@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nutomic.ensichat" >
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
@ -16,6 +19,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".bluetooth.ChatService" />
</application>
</manifest>

View file

@ -9,4 +9,6 @@
<string name="no_contacts_found">No contacts found :(</string>
<string name="bluetooth_required">Bluetooth is required for this app.</string>
</resources>

View file

@ -1,15 +1,31 @@
package com.nutomic.ensichat.activities
import android.app.Activity
import android.bluetooth.BluetoothAdapter
import android.content._
import android.os.Bundle
import android.widget.Toast
import com.nutomic.ensichat.R
class MainActivity extends Activity {
private final val REQUEST_ENABLE_BLUETOOTH = 1
override def onCreate(savedInstanceState: Bundle): Unit = {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val intent: Intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
startActivityForResult(intent, REQUEST_ENABLE_BLUETOOTH)
}
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent): Unit = {
requestCode match {
case REQUEST_ENABLE_BLUETOOTH =>
if (resultCode != Activity.RESULT_OK) {
Toast.makeText(this, R.string.bluetooth_required, Toast.LENGTH_LONG).show()
finish()
}
}
}
}