2 * Copyright (C) 2015 The Realtek Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.realtek.rtkbt.AutoPairUIDemo;
19 import android.content.BroadcastReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.bluetooth.BluetoothAdapter;
23 import android.bluetooth.BluetoothRtkbt;
24 import android.bluetooth.BluetoothDevice;
25 import android.util.Log;
26 import android.widget.Toast;
27 import android.util.Log;
28 import java.util.HashMap;
32 *BluetoothRTKAutoPairBroadcastReceiver sync state with bluetooth,
33 *STATE_ON start BluetoothRTKAutoPairService
34 *STATE_TURNING_OFF stop BluetoothRTKAutoPairService
38 public class rtkbtAutoPairUIDemoReceiver extends BroadcastReceiver {
39 private static final String TAG = "<===AutoPairUIDemoReceiver===>";
40 private static final boolean RTK_DBG = true;
41 private static final String RTKBT_AUTOPAIR_MESSAGE = "com.realtek.autopair.message";
42 private static final String RTKBT_AUTOPAIR_MESSAGE_FIELD_RCUADDR = "com.realtek.autopair.message.rcuaddr";
43 private static final String RTKBT_AUTOPAIR_MESSAGE_FIELD_MESSAGE_ID = "com.realtek.autopair.message.id";
44 private static final String RTKBT_AUTOPAIR_MESSAGE_FIELD_DATA = "com.realtek.autopair.message.data";
46 private static final int RTKBT_AUTOPAIR_State_Idle = 0;
47 private static final int RTKBT_AUTOPAIR_State_Found = 1;
48 private static final int RTKBT_AUTOPAIR_State_RemoveBond = 2;
49 private static final int RTKBT_AUTOPAIR_State_BLEBond = 3;
50 private static final int RTKBT_AUTOPAIR_State_ClassicBond = 4;
51 private static final int RTKBT_AUTOPAIR_State_SaveNewRCU = 5;
52 private static final int RTKBT_AUTOPAIR_State_PairSuccess_to_connect = 6;
53 private static final int RTKBT_AUTOPAIR_State_ConnectSuccess = 7;
55 private static final int RTKBT_AUTOPAIR_State_PairFail = 0x101;
56 private static final int RTKBT_AUTOPAIR_State_PairTimeout = 0x102;
57 private static final int RTKBT_AUTOPAIR_State_ConnectFail = 0x103;
60 public void onReceive(Context context, Intent intent) {
61 Log.i(TAG, "receive intent:" + intent.getAction());
63 if(intent.getAction().equals(RTKBT_AUTOPAIR_MESSAGE)) {
64 Log.d(TAG, "RTKBT_AUTOPAIR_MESSAGE: ID:"+intent.getIntExtra(RTKBT_AUTOPAIR_MESSAGE_FIELD_MESSAGE_ID, 0)+" ADDR:"+intent.getStringExtra(RTKBT_AUTOPAIR_MESSAGE_FIELD_RCUADDR)+" DATA:"+intent.getByteArrayExtra(RTKBT_AUTOPAIR_MESSAGE_FIELD_DATA));
65 ShowMessage(context, intent);
68 private void ShowMessage(Context context, Intent intent)
70 int message_id = intent.getIntExtra(RTKBT_AUTOPAIR_MESSAGE_FIELD_MESSAGE_ID, 0);
71 String rcuaddr = intent.getStringExtra(RTKBT_AUTOPAIR_MESSAGE_FIELD_RCUADDR);
72 byte[] data =intent.getByteArrayExtra(RTKBT_AUTOPAIR_MESSAGE_FIELD_DATA);
75 case RTKBT_AUTOPAIR_State_Found:
76 Toast.makeText(context,"Found RCU("+rcuaddr+")",Toast.LENGTH_LONG).show();
78 case RTKBT_AUTOPAIR_State_RemoveBond:
79 Toast.makeText(context,"RCU("+rcuaddr+") Remove Old RCU Bonding Info",Toast.LENGTH_LONG).show();
81 case RTKBT_AUTOPAIR_State_BLEBond:
82 Toast.makeText(context,"RCU("+rcuaddr+") Start BLE Bonding",Toast.LENGTH_LONG).show();
84 case RTKBT_AUTOPAIR_State_ClassicBond:
85 Toast.makeText(context,"RCU("+rcuaddr+") Start BREDR Bonding",Toast.LENGTH_LONG).show();
87 case RTKBT_AUTOPAIR_State_SaveNewRCU:
88 Toast.makeText(context,"RCU("+rcuaddr+") Save New RCU Bonding Info",Toast.LENGTH_LONG).show();
90 case RTKBT_AUTOPAIR_State_PairSuccess_to_connect:
91 Toast.makeText(context,"RCU("+rcuaddr+") Connecting to RCU",Toast.LENGTH_LONG).show();
93 case RTKBT_AUTOPAIR_State_ConnectSuccess:
94 Toast.makeText(context,"RCU("+rcuaddr+") Connected to RCU, Pair success",Toast.LENGTH_LONG).show();
96 case RTKBT_AUTOPAIR_State_PairFail:
97 Toast.makeText(context,"RCU("+rcuaddr+") Pair Failed",Toast.LENGTH_LONG).show();
99 case RTKBT_AUTOPAIR_State_PairTimeout:
100 Toast.makeText(context,"RCU("+rcuaddr+") Pair Timeout",Toast.LENGTH_LONG).show();
102 case RTKBT_AUTOPAIR_State_ConnectFail:
103 Toast.makeText(context,"RCU("+rcuaddr+") Connect Fail",Toast.LENGTH_LONG).show();