Java Code Examples for android.bluetooth.BluetoothAdapter#setName()

The following examples show how to use android.bluetooth.BluetoothAdapter#setName() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void setDiscoverable() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter == null) {
        return;
    }

    // change name if necessary
    String originalName = adapter.getName();
    if (originalName.lastIndexOf(_deviceNamePostFix) != originalName.length() - _deviceNamePostFix.length()) {
        if (_connectionHelperListener != null) {
            _connectionHelperListener.onAdapterNameChange(originalName);
        }

        Log.d(TAG, "setDiscoverable: Bluetooth device name set to " + (originalName + _deviceNamePostFix));
        adapter.setName(originalName + _deviceNamePostFix);
    }

    // set discoverable if necessary
    if (adapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
        _activity.startActivity(discoverableIntent);
    }
}
 
Example 2
Source Project: tilt-game-android   File: ServerLobbyFragment.java    License: MIT License 6 votes vote down vote up
private void setDiscoverable() {
    Log.d(TAG, "setDiscoverable: ");

    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter == null) {
        return;
    }

    // change name if necessary
    String originalName = adapter.getName();
    if (originalName.lastIndexOf(GoogleFlipGameApplication.DEVICE_POSTFIX) != originalName.length() - GoogleFlipGameApplication.DEVICE_POSTFIX.length()) {
        GoogleFlipGameApplication.setOriginalBluetoothDeviceName(originalName);

        Log.d(TAG, "setDiscoverable: Bluetooth device name set to " + (originalName + GoogleFlipGameApplication.DEVICE_POSTFIX));
        adapter.setName(originalName + GoogleFlipGameApplication.DEVICE_POSTFIX);
    }

    // set discoverable if necessary
    if (adapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
        Log.d(TAG, "setDiscoverable: scan mode is not discoverable, starting activity with code " + ActivityRequestCode.REQUEST_ENABLE_SCAN);
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120);
        getActivity().startActivityForResult(discoverableIntent, ActivityRequestCode.REQUEST_ENABLE_SCAN);
    }
}
 
Example 3
public void setLocalBluetoothName(String name) {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter != null) {
        bluetoothAdapter.setName(name);
    } else {
        Log.w(TAG, "Trying to set bluetooth name with null adapter");
    }
}
 
Example 4
public static void restoreBluetoothDeviceName() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null && sBluetoothDeviceName != null) {
        // restore bluetooth device name
        adapter.setName(sBluetoothDeviceName);
    }
}
 
Example 5
public static void prependRumblePrefixToDeviceName(String prefix) {
    BluetoothAdapter adapter = BluetoothUtil.getBluetoothAdapter(RumbleApplication.getContext());
    if (adapter == null)
        return;
    String name = adapter.getName();
    if(name == null)
        return;
    if(name.startsWith(prefix))
        return;
    else
        adapter.setName(prefix+name);
}
 
Example 6
public static void unprependRumblePrefixFromDeviceName(String prefix) {
    BluetoothAdapter adapter = BluetoothUtil.getBluetoothAdapter(RumbleApplication.getContext());
    if (adapter == null)
        return;
    String name = adapter.getName();
    if(name == null)
        return;
    if(name.startsWith(prefix))
        adapter.setName(name.substring(prefix.length()));
    else
        return;
}