Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.google.android.car.kitchensink.bluetooth; |
| 18 | |
Anthony Chen | d12cd77 | 2018-04-16 16:20:44 -0700 | [diff] [blame] | 19 | import android.Manifest; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 20 | import android.annotation.TargetApi; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 21 | import android.app.PendingIntent; |
| 22 | import android.bluetooth.BluetoothAdapter; |
| 23 | import android.bluetooth.BluetoothDevice; |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 24 | import android.bluetooth.BluetoothDevicePicker; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 25 | import android.bluetooth.BluetoothMapClient; |
| 26 | import android.bluetooth.BluetoothProfile; |
| 27 | import android.content.BroadcastReceiver; |
| 28 | import android.content.Context; |
| 29 | import android.content.Intent; |
| 30 | import android.content.IntentFilter; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 31 | import android.content.pm.PackageManager; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 32 | import android.net.Uri; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 33 | import android.os.Build; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 34 | import android.os.Bundle; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 35 | import android.telecom.PhoneAccount; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 36 | import android.util.Log; |
| 37 | import android.view.LayoutInflater; |
| 38 | import android.view.View; |
| 39 | import android.view.ViewGroup; |
| 40 | import android.widget.Button; |
| 41 | import android.widget.CheckBox; |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 42 | import android.widget.EditText; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 43 | import android.widget.TextView; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 44 | import android.widget.Toast; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 45 | |
Anthony Chen | d12cd77 | 2018-04-16 16:20:44 -0700 | [diff] [blame] | 46 | import androidx.annotation.Nullable; |
| 47 | import androidx.fragment.app.Fragment; |
| 48 | |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 49 | import com.google.android.car.kitchensink.KitchenSinkActivity; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 50 | import com.google.android.car.kitchensink.R; |
| 51 | |
| 52 | import java.util.List; |
| 53 | |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 54 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 55 | public class MapMceTestFragment extends Fragment { |
| 56 | static final String MESSAGE_TO_SEND = "Im Busy Driving"; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 57 | static final String NEW_MESSAGE_TO_SEND = "This is new msg"; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 58 | private static final String TAG = "CAR.BLUETOOTH.KS"; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 59 | private static final int SEND_SMS_PERMISSIONS_REQUEST = 1; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 60 | BluetoothMapClient mMapProfile; |
| 61 | BluetoothAdapter mBluetoothAdapter; |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 62 | Button mDevicePicker; |
| 63 | Button mDeviceDisconnect; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 64 | TextView mMessage; |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 65 | EditText mOriginator; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 66 | EditText mSmsTelNum; |
Joseph Pirozzo | a90995a | 2016-10-13 09:48:50 -0700 | [diff] [blame] | 67 | TextView mOriginatorDisplayName; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 68 | CheckBox mSent; |
| 69 | CheckBox mDelivered; |
| 70 | TextView mBluetoothDevice; |
| 71 | PendingIntent mSentIntent; |
| 72 | PendingIntent mDeliveredIntent; |
| 73 | NotificationReceiver mTransmissionStatusReceiver; |
| 74 | Object mLock = new Object(); |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 75 | private KitchenSinkActivity mActivity; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 76 | private Intent mSendIntent; |
| 77 | private Intent mDeliveryIntent; |
| 78 | |
| 79 | @Override |
| 80 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, |
| 81 | @Nullable Bundle savedInstanceState) { |
| 82 | View v = inflater.inflate(R.layout.sms_received, container, false); |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 83 | mActivity = (KitchenSinkActivity) getHost(); |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 84 | Button reply = (Button) v.findViewById(R.id.reply); |
| 85 | Button checkMessages = (Button) v.findViewById(R.id.check_messages); |
| 86 | mBluetoothDevice = (TextView) v.findViewById(R.id.bluetoothDevice); |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 87 | Button sendNewMsg = (Button) v.findViewById(R.id.sms_new_message); |
| 88 | mSmsTelNum = (EditText) v.findViewById(R.id.sms_tel_num); |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 89 | mOriginator = (EditText) v.findViewById(R.id.messageOriginator); |
Joseph Pirozzo | a90995a | 2016-10-13 09:48:50 -0700 | [diff] [blame] | 90 | mOriginatorDisplayName = (TextView) v.findViewById(R.id.messageOriginatorDisplayName); |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 91 | mSent = (CheckBox) v.findViewById(R.id.sent_checkbox); |
| 92 | mDelivered = (CheckBox) v.findViewById(R.id.delivered_checkbox); |
| 93 | mSendIntent = new Intent(BluetoothMapClient.ACTION_MESSAGE_SENT_SUCCESSFULLY); |
| 94 | mDeliveryIntent = new Intent(BluetoothMapClient.ACTION_MESSAGE_DELIVERED_SUCCESSFULLY); |
| 95 | mMessage = (TextView) v.findViewById(R.id.messageContent); |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 96 | mDevicePicker = (Button) v.findViewById(R.id.bluetooth_pick_device); |
| 97 | mDeviceDisconnect = (Button) v.findViewById(R.id.bluetooth_disconnect_device); |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 98 | //TODO add manual entry option for phone number |
| 99 | reply.setOnClickListener(new View.OnClickListener() { |
| 100 | @Override |
| 101 | public void onClick(View view) { |
| 102 | sendMessage(new Uri[]{Uri.parse(mOriginator.getText().toString())}, |
| 103 | MESSAGE_TO_SEND); |
| 104 | } |
| 105 | }); |
| 106 | |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 107 | sendNewMsg.setOnClickListener(new View.OnClickListener() { |
| 108 | @Override |
| 109 | public void onClick(View view) { |
| 110 | String s = mSmsTelNum.getText().toString(); |
| 111 | Toast.makeText(getContext(), "sending msg to " + s, Toast.LENGTH_SHORT).show(); |
| 112 | Uri.Builder builder = new Uri.Builder(); |
| 113 | Uri uri = builder.appendPath(s).scheme(PhoneAccount.SCHEME_TEL).build(); |
| 114 | sendMessage(new Uri[]{uri}, NEW_MESSAGE_TO_SEND); |
| 115 | } |
| 116 | }); |
| 117 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 118 | checkMessages.setOnClickListener(new View.OnClickListener() { |
| 119 | @Override |
| 120 | public void onClick(View view) { |
| 121 | getMessages(); |
| 122 | } |
| 123 | }); |
| 124 | |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 125 | // Pick a bluetooth device |
| 126 | mDevicePicker.setOnClickListener(new View.OnClickListener() { |
| 127 | @Override |
| 128 | public void onClick(View view) { |
| 129 | launchDevicePicker(); |
| 130 | } |
| 131 | }); |
| 132 | mDeviceDisconnect.setOnClickListener(new View.OnClickListener() { |
| 133 | @Override |
| 134 | public void onClick(View view) { |
| 135 | disconnectDevice(mBluetoothDevice.getText().toString()); |
| 136 | } |
| 137 | }); |
| 138 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 139 | mTransmissionStatusReceiver = new NotificationReceiver(); |
| 140 | return v; |
| 141 | } |
| 142 | |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 143 | void launchDevicePicker() { |
| 144 | IntentFilter filter = new IntentFilter(); |
| 145 | filter.addAction(BluetoothDevicePicker.ACTION_DEVICE_SELECTED); |
| 146 | getContext().registerReceiver(mPickerReceiver, filter); |
| 147 | |
| 148 | Intent intent = new Intent(BluetoothDevicePicker.ACTION_LAUNCH); |
| 149 | intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 150 | getContext().startActivity(intent); |
| 151 | } |
| 152 | |
| 153 | void disconnectDevice(String device) { |
| 154 | mMapProfile.disconnect(mBluetoothAdapter.getRemoteDevice((device))); |
| 155 | } |
| 156 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 157 | @Override |
| 158 | public void onResume() { |
| 159 | super.onResume(); |
| 160 | |
| 161 | mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); |
| 162 | mBluetoothAdapter.getProfileProxy(getContext(), new MapServiceListener(), |
| 163 | BluetoothProfile.MAP_CLIENT); |
| 164 | |
| 165 | IntentFilter intentFilter = new IntentFilter(); |
| 166 | intentFilter.addAction(BluetoothMapClient.ACTION_MESSAGE_SENT_SUCCESSFULLY); |
| 167 | intentFilter.addAction(BluetoothMapClient.ACTION_MESSAGE_DELIVERED_SUCCESSFULLY); |
| 168 | intentFilter.addAction(BluetoothMapClient.ACTION_MESSAGE_RECEIVED); |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 169 | intentFilter.addAction(BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED); |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 170 | getContext().registerReceiver(mTransmissionStatusReceiver, intentFilter); |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public void onPause() { |
| 175 | super.onPause(); |
| 176 | getContext().unregisterReceiver(mTransmissionStatusReceiver); |
| 177 | } |
| 178 | |
| 179 | private void getMessages() { |
| 180 | synchronized (mLock) { |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 181 | BluetoothDevice remoteDevice; |
| 182 | try { |
| 183 | remoteDevice = mBluetoothAdapter.getRemoteDevice( |
| 184 | mBluetoothDevice.getText().toString()); |
| 185 | } catch (java.lang.IllegalArgumentException e) { |
| 186 | Log.e(TAG, e.toString()); |
| 187 | return; |
| 188 | } |
| 189 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 190 | if (mMapProfile != null) { |
| 191 | Log.d(TAG, "Getting Messages"); |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 192 | mMapProfile.getUnreadMessages(remoteDevice); |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | private void sendMessage(Uri[] recipients, String message) { |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 198 | if (mActivity.checkSelfPermission(Manifest.permission.SEND_SMS) |
| 199 | != PackageManager.PERMISSION_GRANTED) { |
| 200 | Log.d(TAG,"Don't have SMS permission in kitchesink app. Requesting it"); |
| 201 | mActivity.requestPermissions(new String[]{Manifest.permission.SEND_SMS}, |
| 202 | SEND_SMS_PERMISSIONS_REQUEST); |
| 203 | Toast.makeText(getContext(), "Try again after granting SEND_SMS perm!", |
| 204 | Toast.LENGTH_SHORT).show(); |
| 205 | return; |
| 206 | } |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 207 | synchronized (mLock) { |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 208 | BluetoothDevice remoteDevice; |
| 209 | try { |
| 210 | remoteDevice = mBluetoothAdapter.getRemoteDevice( |
| 211 | mBluetoothDevice.getText().toString()); |
| 212 | } catch (java.lang.IllegalArgumentException e) { |
| 213 | Log.e(TAG, e.toString()); |
| 214 | return; |
| 215 | } |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 216 | mSent.setChecked(false); |
| 217 | mDelivered.setChecked(false); |
| 218 | if (mMapProfile != null) { |
| 219 | Log.d(TAG, "Sending reply"); |
| 220 | if (recipients == null) { |
| 221 | Log.d(TAG, "Recipients is null"); |
| 222 | return; |
| 223 | } |
| 224 | if (mBluetoothDevice == null) { |
| 225 | Log.d(TAG, "BluetoothDevice is null"); |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | mSentIntent = PendingIntent.getBroadcast(getContext(), 0, mSendIntent, |
| 230 | PendingIntent.FLAG_ONE_SHOT); |
| 231 | mDeliveredIntent = PendingIntent.getBroadcast(getContext(), 0, mDeliveryIntent, |
| 232 | PendingIntent.FLAG_ONE_SHOT); |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 233 | Log.d(TAG,"Sending message in kitchesink app: " + message); |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 234 | mMapProfile.sendMessage( |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 235 | remoteDevice, |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 236 | recipients, message, mSentIntent, mDeliveredIntent); |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 241 | @Override |
| 242 | public void onRequestPermissionsResult(int requestCode, String[] permissions, |
| 243 | int[] grantResults) { |
| 244 | Log.d(TAG, "onRequestPermissionsResult reqCode=" + requestCode); |
| 245 | if (SEND_SMS_PERMISSIONS_REQUEST == requestCode) { |
| 246 | for (int i=0; i<permissions.length; i++) { |
| 247 | if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { |
| 248 | if (permissions[i] == Manifest.permission.SEND_SMS) { |
| 249 | Log.d(TAG, "Got the SEND_SMS perm"); |
| 250 | return; |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 257 | class MapServiceListener implements BluetoothProfile.ServiceListener { |
| 258 | @Override |
| 259 | public void onServiceConnected(int profile, BluetoothProfile proxy) { |
| 260 | synchronized (mLock) { |
| 261 | mMapProfile = (BluetoothMapClient) proxy; |
| 262 | List<BluetoothDevice> connectedDevices = proxy.getConnectedDevices(); |
| 263 | if (connectedDevices.size() > 0) { |
| 264 | mBluetoothDevice.setText(connectedDevices.get(0).getAddress()); |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | @Override |
| 270 | public void onServiceDisconnected(int profile) { |
| 271 | synchronized (mLock) { |
| 272 | mMapProfile = null; |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | private class NotificationReceiver extends BroadcastReceiver { |
| 278 | @Override |
| 279 | public void onReceive(Context context, Intent intent) { |
| 280 | String action = intent.getAction(); |
| 281 | synchronized (mLock) { |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 282 | if (action.equals(BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED)) { |
| 283 | if (intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0) |
| 284 | == BluetoothProfile.STATE_CONNECTED) { |
| 285 | mBluetoothDevice.setText(((BluetoothDevice) intent.getParcelableExtra( |
| 286 | BluetoothDevice.EXTRA_DEVICE)).getAddress()); |
| 287 | } else if (intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0) |
| 288 | == BluetoothProfile.STATE_DISCONNECTED) { |
| 289 | mBluetoothDevice.setText("Disconnected"); |
| 290 | } |
| 291 | } else if (action.equals(BluetoothMapClient.ACTION_MESSAGE_SENT_SUCCESSFULLY)) { |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 292 | mSent.setChecked(true); |
| 293 | } else if (action.equals( |
| 294 | BluetoothMapClient.ACTION_MESSAGE_DELIVERED_SUCCESSFULLY)) { |
| 295 | mDelivered.setChecked(true); |
| 296 | } else if (action.equals(BluetoothMapClient.ACTION_MESSAGE_RECEIVED)) { |
Srinivas Visvanathan | 3bb97c6 | 2017-03-08 16:15:07 -0800 | [diff] [blame] | 297 | String senderUri = |
| 298 | intent.getStringExtra(BluetoothMapClient.EXTRA_SENDER_CONTACT_URI); |
| 299 | if (senderUri == null) { |
| 300 | senderUri = "<null>"; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Srinivas Visvanathan | 3bb97c6 | 2017-03-08 16:15:07 -0800 | [diff] [blame] | 303 | String senderName = intent.getStringExtra( |
Srinivas Visvanathan | 6b90bbf | 2017-03-03 10:01:09 -0800 | [diff] [blame] | 304 | BluetoothMapClient.EXTRA_SENDER_CONTACT_NAME); |
Srinivas Visvanathan | 3bb97c6 | 2017-03-08 16:15:07 -0800 | [diff] [blame] | 305 | if (senderName == null) { |
| 306 | senderName = "<null>"; |
Joseph Pirozzo | a90995a | 2016-10-13 09:48:50 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 309 | mMessage.setText(intent.getStringExtra(android.content.Intent.EXTRA_TEXT)); |
Srinivas Visvanathan | 3bb97c6 | 2017-03-08 16:15:07 -0800 | [diff] [blame] | 310 | mOriginator.setText(senderUri); |
| 311 | mOriginatorDisplayName.setText(senderName); |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | } |
| 315 | } |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 316 | |
| 317 | private final BroadcastReceiver mPickerReceiver = new BroadcastReceiver() { |
| 318 | @Override |
| 319 | public void onReceive(Context context, Intent intent) { |
| 320 | String action = intent.getAction(); |
| 321 | |
| 322 | Log.v(TAG, "mPickerReceiver got " + action); |
| 323 | |
| 324 | if (BluetoothDevicePicker.ACTION_DEVICE_SELECTED.equals(action)) { |
| 325 | BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); |
| 326 | Log.v(TAG, "mPickerReceiver got " + device); |
| 327 | mMapProfile.connect(device); |
| 328 | |
| 329 | // The receiver can now be disabled. |
| 330 | getContext().unregisterReceiver(mPickerReceiver); |
| 331 | } |
| 332 | } |
| 333 | }; |
Anthony Chen | d12cd77 | 2018-04-16 16:20:44 -0700 | [diff] [blame] | 334 | } |