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

The following examples show how to use android.bluetooth.BluetoothAdapter#getName() . 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 static String getDeviceName(){
    String deviceInfo = weMessage.get().getSharedPreferences().getString(weMessage.SHARED_PREFERENCES_DEVICE_INFO, "");

    if (!StringUtils.isEmpty(deviceInfo)) {
        Device device = Device.fromString(deviceInfo);

        if (device != null && device.getManufacturer().equalsIgnoreCase(Build.MANUFACTURER) && device.getModel().equalsIgnoreCase(Build.MODEL)){
            return device.getName();
        }
    }

    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    String deviceName;

    if (adapter != null) {
        deviceName = adapter.getName();
    } else {
        deviceName = getInternalDeviceName();
    }
    return deviceName;
}
 
Example 2
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 3
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 4
public static String getDeviceName(Context context) {
    String name =
            Settings.Global.getString(
                    context.getContentResolver(), Settings.Global.DEVICE_NAME);
    if (name == null) {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        if (adapter != null) {
            name = adapter.getName();
        }
    }
    if (name == null) {
        name = Settings.Secure.getString(context.getContentResolver(), "bluetooth_name");
    }
    if (name == null) {
        name = Build.MANUFACTURER + " " + Build.MODEL;
    }
    return name;
}
 
Example 5
public static String getDeviceName(Context context) {
    if (Version.sdkAboveOrEqual(25)) {
        return ApiTwentySixPlus.getDeviceName(context);
    }

    String name = null;
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null) {
        name = adapter.getName();
    }

    if (name == null) {
        name = Settings.Secure.getString(context.getContentResolver(), "bluetooth_name");
    }
    if (name == null) {
        name = Build.MANUFACTURER + " " + Build.MODEL;
    }
    return name;
}
 
Example 6
public String getLocalBluetoothName() {
    String name = null;
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter != null) {
        name = bluetoothAdapter.getName();
    }
    return name;
}
 
Example 7
Source Project: JsDroidCmd   File: JsSystem.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 判断蓝牙是否有效来判断是否为模拟器
 * 
 * @return true 为模拟器
 */
public static boolean notHasBlueTooth() {
	BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
	if (ba == null) {
		return true;
	} else {
		// 如果有蓝牙不一定是有效的。获取蓝牙名称,若为null 则默认为模拟器
		String name = ba.getName();
		if (TextUtils.isEmpty(name)) {
			return true;
		} else {
			return false;
		}
	}
}
 
Example 8
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 9
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;
}
 
Example 10
Source Project: DeviceConnect-Android   File: BleUtils.java    License: MIT License 2 votes vote down vote up
/**
 * Bluetoothの名前を取得します.
 * @param context このアプリケーションが属するコンテキスト
 * @return Bluetoothの名前、名前が取得できない場合はnullを返却します。
 */
public static String getBluetoothName(@NonNull final Context context) {
    BluetoothAdapter bluetoothAdapter = getAdapter(context);
    return bluetoothAdapter != null ? bluetoothAdapter.getName() : null;
}