Код: Выделить всё
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())
);
}
}
Когда я запускаю рекламу, имя, отображаемое на других устройствах в настройках Bluetooth, изменится на случайную строку. Например, «ISUEdvDFSAFEIOWFFD».
И когда я запускаю stopAdvertising(), имя набора будет отображаться правильно.
Я хочу установить его так, чтобы даже при запуске startAdvertising() оно отображалось как « мое устройство», которое я установил.
Подробнее здесь: https://stackoverflow.com/questions/781 ... onnect-api