Android车载蓝牙文件传输自动接受和弹窗接收 (Android5.1 & Android 7.1)

30 篇文章 0 订阅
2 篇文章 0 订阅

目录

 

Android 5.1 修改 patch (弹窗接收文件 和 自动接收文件)

(一).弹窗需要车机端点击确认之后才进行接收文件的path

(二).手机端传输,车机端自动进行接收,不需要用户点击确定的接收模式

 

Android7.1 (弹窗接收文件 和 自动接收文件)

(一).弹窗需要车机端点击确认之后才进行接收文件的path

(二),手机端传输,车机端自动进行接收,不需要用户点击确定的接收模式


车机蓝牙作为从端的存在,限制了不少的功能,目前公司需要做车载蓝牙文件传输功能,蓝牙本来是支持文件传输弹窗操作的,但是车载系统都会把原生的systemUI进行了定制,修改成自己定制的systemUI,导致原生很多的状态栏目通知不能使用,那么蓝牙传输的时候接收文件的弹窗也是不能使用,用户不能点击确认接收按钮,我们需要将系统蓝牙文件的传输方式做对应的修改才能进行文件的传输.本文主要做了两种方式的修改,第一种是弹窗用户确认方式,第二种是不需要确认直接接收文件,接收的文件都在 /sdcard/bluetooth/目录之下.

 

如果不知道如何进主从设置的可以看看Android 7.1 系统 部分功能修改 汇总 这篇文章设置蓝牙的主从模式 . 如果对蓝牙感兴趣的可以看看 Android 蓝牙启动流程(以及设置蓝牙为作为sink模式 & 接收端模式)

 

文件传输的前提是首先将profile_supported_opp 设置成true方式打开文件传输功能.

packages/apps/Bluetooth/res/values/config.xml 

diff --git a/apps/Bluetooth/res/values/config.xml b/apps/Bluetooth/res/values/config.xml
index 90e513d..382bf30 100644
--- a/apps/Bluetooth/res/values/config.xml
+++ b/apps/Bluetooth/res/values/config.xml
@@ -19,6 +19,7 @@
     <bool name="profile_supported_hs_hfp">true</bool>
     <bool name="profile_supported_hfpclient">false</bool>
     <bool name="profile_supported_hid">true</bool>
+    <bool name="profile_supported_opp">true</bool>
     <bool name="profile_supported_pan">true</bool>
     <bool name="profile_supported_pbap">true</bool>

 

Android 5.1 修改 patch (弹窗接收文件 和 自动接收文件)

(一).弹窗需要车机端点击确认之后才进行接收文件的path

packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java


iff --git a/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java b/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
index 75f9e75..17f2518 100755
--- a/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
+++ b/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
@@ -538,7 +538,6 @@ class BluetoothOppNotification {
             int id = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare._ID));
             long timeStamp = cursor.getLong(cursor.getColumnIndexOrThrow(BluetoothShare.TIMESTAMP));
             Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + id);

             Notification n = new Notification();
             n.icon = R.drawable.bt_incomming_file_notification;
             n.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
@@ -550,6 +549,18 @@ class BluetoothOppNotification {
             intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
             intent.setDataAndNormalize(contentUri);

+            //弹窗确认接收模式仅用如下四句话 弹窗逻辑系统自带
+            intent = new Intent(Constants.ACTION_INCOMING_FILE_CONFIRM);
+            intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
+            intent.setDataAndNormalize(contentUri);
+            mContext.sendBroadcast(intent);
             n.when = timeStamp;
             n.color = mContext.getResources().getColor(
                     com.android.internal.R.color.system_notification_accent_color);

(二).手机端传输,车机端自动进行接收,不需要用户点击确定的接收模式

packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java


iff --git a/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java b/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
index 75f9e75..17f2518 100755
--- a/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
+++ b/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
@@ -538,7 +538,6 @@ class BluetoothOppNotification {
             int id = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare._ID));
             long timeStamp = cursor.getLong(cursor.getColumnIndexOrThrow(BluetoothShare.TIMESTAMP));
             Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + id);

             Notification n = new Notification();
             n.icon = R.drawable.bt_incomming_file_notification;
             n.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
@@ -550,6 +549,18 @@ class BluetoothOppNotification {
             intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
             intent.setDataAndNormalize(contentUri);


+
+            //默认自动接收模式 Constants.ACTION_ACCEPT
+            intent = new Intent(Constants.ACTION_ACCEPT);
+            intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
+            intent.setDataAndNormalize(contentUri);
+            mContext.sendBroadcast(intent);
+
             n.when = timeStamp;
             n.color = mContext.getResources().getColor(
                     com.android.internal.R.color.system_notification_accent_color);

packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppReceiver.java

diff --git a/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppReceiver.java b/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
index 616c430..6225888 100755
--- a/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
+++ b/packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
@@ -125,6 +125,14 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
                 toastMsg = context.getString(R.string.bt_toast_4, deviceName);
             }
             Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
+        } else if (action.equals(Constants.ACTION_ACCEPT)) {
+            
+            //默认自动接收模式 Constants.ACTION_ACCEPT
+              
+            if (V) Log.v(TAG, "Receiver ACTION_ACCEPT");
+            Uri uri = intent.getData();
+            ContentValues values = new ContentValues();
+            values.put(BluetoothShare.USER_CONFIRMATION, BluetoothShare.USER_CONFIRMATION_CONFIRMED);
+            context.getContentResolver().update(uri, values, null, null);
+
         } else if (action.equals(Constants.ACTION_INCOMING_FILE_CONFIRM)) {
             if (V) Log.v(TAG, "Receiver ACTION_INCOMING_FILE_CONFIRM");

packages/apps/Bluetooth/src/com/android/bluetooth/opp/Constants.java

packages/apps/Bluetooth/src/com/android/bluetooth/opp/Constants.java

diff --git a/packages/apps/Bluetooth/src/com/android/bluetooth/opp/Constants.java b/packages/apps/Bluetooth/src/com/android/bluetooth/opp/Constants.java
index 6e9609a..b1ca497 100755
--- a/packages/apps/Bluetooth/src/com/android/bluetooth/opp/Constants.java
+++ b/packages/apps/Bluetooth/src/com/android/bluetooth/opp/Constants.java
@@ -52,6 +52,9 @@ import android.util.Log;
  * Bluetooth OPP internal constants definition
  */
 public class Constants {

+     //默认自动接收模式 Constants.ACTION_ACCEPT
+    public static final String ACTION_ACCEPT = "android.btopp.intent.action.ACCEPT";
+
     /** Tag used for debugging/logging */
     public static final String TAG = "[Bluetooth.OPP]BluetoothOpp";

 

Android7.1 (弹窗接收文件 和 自动接收文件)

(一).弹窗需要车机端点击确认之后才进行接收文件的path

packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java

diff --git a/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java b/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
index 6f92e95..76ea10b 100644
--- a/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
+++ b/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
@@ -563,6 +563,8 @@
           Intent baseIntent = new Intent().setDataAndNormalize(contentUri)
               .setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
 
+          mContext.sendBroadcast(new Intent(baseIntent).setAction(Constants.ACTION_INCOMING_FILE_CONFIRM));
+
           Notification n = new Notification.Builder(mContext)
               .setOnlyAlertOnce(true)
               .setOngoing(true)

(二),手机端传输,车机端自动进行接收,不需要用户点击确定的接收模式

packages/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java

diff --git a/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java b/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
index 6f92e95..76ea10b 100644
--- a/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
+++ b/apps/Bluetooth/src/com/android/bluetooth/opp/BluetoothOppNotification.java
@@ -563,6 +563,8 @@
           Intent baseIntent = new Intent().setDataAndNormalize(contentUri)
               .setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
 
+          mContext.sendBroadcast(new Intent(baseIntent).setAction(Constants.ACTION_ACCEPT));
+
           Notification n = new Notification.Builder(mContext)
               .setOnlyAlertOnce(true)
               .setOngoing(true)

 

 

 

 

 

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值