RK Android7.1 设置->蓝牙->已断开连接 Android6.0 直接弹窗

 

一. Android7.1 连手机蓝牙 显示 蓝牙已断开连接

1.1. /frameworks/base/packages/SettingsLib/res/values-zh-rCN/strings.xml

1
<string name="bluetooth_disconnected" msgid="6557104142667339895">"已断开连接"</string>

1.2.蓝牙配对 K:\ZK-Rxxx_7.1_RK3399_Firmware\ZK_RXXX_RK3399_ANDROID7.1\packages\apps\Settings\src\com\android\settings\bluetooth\BluetoothSettings.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@Override
public void setListening(boolean listening) {
    BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
    if (defaultAdapter == null) return;
    if (listening) {
        mEnabled = defaultAdapter.isEnabled();
        mConnected =
                defaultAdapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED;
 
        Log.d("gatsby","state aaa -> "+ BluetoothAdapter.STATE_CONNECTED);
        Log.d("gatsby","state bbb -> "+ defaultAdapter.getConnectionState());
             
                 
        mSummaryLoader.setSummary(this, getSummary());
        mBluetoothManager.getEventManager().registerCallback(this);
    } else {
        mBluetoothManager.getEventManager().unregisterCallback(this);
    }
}
 
private CharSequence getSummary() {
     
    Log.d("gatsby","!mEnabled -> "+ !mEnabled + " mConnected ->"+mConnected);
 
    return mContext.getString(!mEnabled ? R.string.bluetooth_disabled
            : mConnected ? R.string.bluetooth_connected
            : R.string.bluetooth_disconnected);
}

a. Log.d("gatsby","!mEnabled -> "+ !mEnabled + " mConnected ->"+mConnected);
mEnabled ? R.string.bluetooth_disabled: mConnected ? R.string.bluetooth_connected: R.string.bluetooth_disconnected
mEnabled ?"disabled" : mConnected ? "bluetooth_connected" : "bluetooth_disconnected";
打开蓝牙开关 未连接蓝牙 !mEnabled -> false mConnected ->false

b.mConnected = defaultAdapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED;

1
2
defaultAdapter.getConnectionState() -> 0
BluetoothAdapter.STATE_CONNECTED -> 2

1.3.Android检查设备连接状态

K:\ZK-Rxxx_7.1_RK3399_Firmware\ZK_RXXX_RK3399_ANDROID7.1\frameworks\base\core\java\android\bluetooth\BluetoothAdapter.java  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/** The profile is in disconnected state */
public static final int STATE_DISCONNECTED  = 0;   
 
 
/**
 * Get the current connection state of the local Bluetooth adapter.
 * This can be used to check whether the local Bluetooth adapter is connected
 * to any profile of any other remote Bluetooth Device.
 *
 * <p> Use this function along with {@link #ACTION_CONNECTION_STATE_CHANGED}
 * intent to get the connection state of the adapter.
 *
 * @return One of {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTED},
 * {@link #STATE_CONNECTING} or {@link #STATE_DISCONNECTED}
 *
 * @hide
 */
public int getConnectionState() {
    if (getState() != STATE_ON) return BluetoothAdapter.STATE_DISCONNECTED;
    try {
        mServiceLock.readLock().lock();
        if (mService != null) return mService.getAdapterConnectionState();
    } catch (RemoteException e) {
        Log.e(TAG, "getConnectionState:", e);
    } finally {
        mServiceLock.readLock().unlock();
    }
    return BluetoothAdapter.STATE_DISCONNECTED;
}

调用BluetoothAdapter中的getConnectionState()方法,直接检查是否存在连接状态的蓝牙设备存在 不能检测出手机发出的蓝牙 可以检测出蓝牙耳机  

1
2
3
4
5
6
7
8
/** The profile is in disconnected state */
public static final int STATE_DISCONNECTED  = 0;
/** The profile is in connecting state */
public static final int STATE_CONNECTING    = 1;
/** The profile is in connected state */
public static final int STATE_CONNECTED     = 2;
/** The profile is in disconnecting state */
public static final int STATE_DISCONNECTING = 3;

 二.Android6.0  蓝牙直接弹窗  

2.1.packages\apps\Bluetooth\src\com\android\bluetooth\btservice\AdapterProperties.java

     void updateFeatureSupport(byte[] val) {  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
--- a/packages/apps/Bluetooth/src/com/android/bluetooth/btservice/AdapterProperties.java
+++ b/packages/apps/Bluetooth/src/com/android/bluetooth/btservice/AdapterProperties.java
@@ -612,11 +612,11 @@ class AdapterProperties {
                        adapterPropertyChangedCallback received before
                        onBluetoothReady */
                     if (mDiscoverableTimeout != 0)
-                      setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE);
+                      setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
                     else /* if timeout == never (0) at startup */
                       setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
                     /* though not always required, this keeps NV up-to date on first-boot after flash */
-                    setDiscoverableTimeout(mDiscoverableTimeout);
+                    setDiscoverableTimeout(0/*mDiscoverableTimeout*/);
             }
         }
     }

2.2.packages\apps\Bluetooth\src\com\android\bluetooth\opp\BluetoothOppNotification.java

  private void updateIncomingFileConfirmNotification() {

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
--- a/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
+++ b/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
@@ -526,6 +526,15 @@ class BluetoothOppNotification {
             n.deleteIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
  
             mNotificationMgr.notify(id, n);
+          
+           Uri uri = intent.getData();
+            Intent in = new Intent(mContext, BluetoothOppIncomingFileConfirmActivity.class);
+            in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            in.setDataAndNormalize(uri);
+            mContext.startActivity(in);
+
+            NotificationManager notGatsby = (NotificationManager)mContext
+                    .getSystemService(Context.NOTIFICATION_SERVICE);
         }
         cursor.close();
     }

  

  

  

posted @   CrushGirl  阅读(724)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示