Insight: fix pairing
This commit is contained in:
parent
b31e328022
commit
5861c0ee6a
|
@ -61,7 +61,7 @@
|
|||
android:minHeight="3dp" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
style="@style/OkCancelButton"
|
||||
style="@style/OkCancelButton.Text"
|
||||
android:id="@+id/ok"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<application>
|
||||
<activity
|
||||
|
|
|
@ -9,6 +9,8 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -20,6 +22,8 @@ import android.widget.TextView;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
@ -54,6 +58,8 @@ public class InsightPairingActivity extends NoSplashAppCompatActivity implements
|
|||
private RecyclerView deviceList;
|
||||
private final DeviceAdapter deviceAdapter = new DeviceAdapter();
|
||||
|
||||
private final int PERMISSION_REQUEST_BLUETOOTH = 30242;
|
||||
|
||||
private InsightConnectionService service;
|
||||
|
||||
private final ServiceConnection serviceConnection = new ServiceConnection() {
|
||||
|
@ -100,6 +106,15 @@ public class InsightPairingActivity extends NoSplashAppCompatActivity implements
|
|||
deviceList.setLayoutManager(new LinearLayoutManager(this));
|
||||
deviceList.setAdapter(deviceAdapter);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
if (ContextCompat.checkSelfPermission(context, "android.permission.BLUETOOTH_CONNECT") != PackageManager.PERMISSION_GRANTED ||
|
||||
ContextCompat.checkSelfPermission(context, "android.permission.BLUETOOTH_SCAN") != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
ActivityCompat.requestPermissions(this, new String[]{"android.permission.BLUETOOTH_SCAN", "android.permission.BLUETOOTH_CONNECT"}, PERMISSION_REQUEST_BLUETOOTH);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bindService(new Intent(this, InsightConnectionService.class), serviceConnection, BIND_AUTO_CREATE);
|
||||
}
|
||||
|
@ -110,8 +125,8 @@ public class InsightPairingActivity extends NoSplashAppCompatActivity implements
|
|||
service.withdrawConnectionRequest(InsightPairingActivity.this);
|
||||
service.unregisterStateCallback(InsightPairingActivity.this);
|
||||
service.unregisterExceptionCallback(InsightPairingActivity.this);
|
||||
}
|
||||
unbindService(serviceConnection);
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@ -195,6 +210,7 @@ public class InsightPairingActivity extends NoSplashAppCompatActivity implements
|
|||
scanning = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == exit) finish();
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/mute"
|
||||
style="@style/OkCancelButton"
|
||||
style="@style/OkCancelButton.Text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="muteClicked"
|
||||
|
@ -59,7 +59,7 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/confirm"
|
||||
style="@style/OkCancelButton"
|
||||
style="@style/OkCancelButton.Text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="confirmClicked"
|
||||
|
|
|
@ -66,14 +66,14 @@
|
|||
android:orientation="horizontal">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
style="@style/OkCancelButton"
|
||||
style="@style/OkCancelButton.Text"
|
||||
android:id="@+id/no"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/no" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
style="@style/OkCancelButton"
|
||||
style="@style/OkCancelButton.Text"
|
||||
android:id="@+id/yes"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -97,7 +97,7 @@
|
|||
android:text="@string/pairing_completed" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
style="@style/OkCancelButton"
|
||||
style="@style/OkCancelButton.Text"
|
||||
android:id="@+id/exit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
Loading…
Reference in a new issue