connectivity-samples icon indicating copy to clipboard operation
connectivity-samples copied to clipboard

BlueTooth device name have changed When i use nearby connections api startAdvertising() function

Open jaehyun0122 opened this issue 11 months ago • 0 comments

i tried to run NearbyConnectionsWalkieTalkie When i run the startAdvertising function of the nearby connection API, the Bluetooth device name displayed on other devices will change. When i run the startAdvertising function, the symptom appears, and when i stopAdvertising, the desired device name returns. I don't know the cause. The DiscoveredEndpointInfo.endpointName value in the onEndPointFound function is ",BrailleSense6", which is the value I want.

Is there a way to prevent the Bluetooth device name from changing? Before startAdvertising() : expected

after startAdvertising() : changed

I ran the following code:

public class NearbyConnectionUI extends HanSystemUI {
private ConnectionsClient mConnectionsClient;

private void startAdvertising(){
        mConnectionsClient
                .startAdvertising(
                        Settings.Secure.getString(mContext.getContentResolver(), "bluetooth_name"),
                        BuildConfig.APPLICATION_ID, // serviceID
                        new ConnectionLifecycleCallback() {

                            @Override
                            public void onConnectionInitiated(@NonNull String endpointID, @NonNull ConnectionInfo connectionInfo) {
                                Log.d(TAG, "onConnectionInitiated: endpointID : " + endpointID + "endpointName : " + connectionInfo.getEndpointName());

                                mNearbyConfirmDlg.setDeviceName(connectionInfo.getEndpointName());
                                mNearbyConfirmDlg.setConnectionConfirmInterface(result -> {
                                    if ("ok".equals(result)) {
                                        acceptConnection(endpointID);
                                    } else {

                                    }
                                });

                                mNearbyConfirmDlg.show();
                            }

                            @Override
                            public void onConnectionResult(@NonNull String endpointID, @NonNull ConnectionResolution connectionsResult) {
                                Log.d(TAG, "onConnectionResult: endpointID : " + endpointID + ", result : " + connectionsResult.getStatus().getStatusCode());
                                if (connectionsResult.getStatus().isSuccess()) {

                                }
                            }

                            @Override
                            public void onDisconnected(@NonNull String endpointID) {
                                Log.d(TAG, "onDisconnected: endpointID : " + endpointID);
                            }
                        },
                        new AdvertisingOptions.Builder().setStrategy(Strategy.P2P_STAR).build()
                )
                .addOnSuccessListener(
                        unusedResult ->
                                Log.d(TAG, "advertising success. endpointName : " +
                                        Settings.Global.getString(mContext.getContentResolver(), Settings.Global.DEVICE_NAME))
                )
                .addOnFailureListener(
                        exception ->
                                Log.d(TAG, "advertising fail. exception : " + exception.getMessage())
                );
}
}

jaehyun0122 avatar Mar 12 '24 02:03 jaehyun0122