Java Code Examples for no.nordicsemi.android.log.Logger#newSession()

The following examples show how to use no.nordicsemi.android.log.Logger#newSession() . 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
Source File: NrfMeshRepository.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Connect to peripheral
 *
 * @param context          Context
 * @param device           {@link ExtendedBluetoothDevice} device
 * @param connectToNetwork True if connecting to an unprovisioned node or proxy node
 */
void connect(final Context context, final ExtendedBluetoothDevice device, final boolean connectToNetwork) {
    mMeshNetworkLiveData.setNodeName(device.getName());
    mIsProvisioningComplete = false;
    mIsCompositionDataReceived = false;
    mIsDefaultTtlReceived = false;
    mIsAppKeyAddCompleted = false;
    mIsNetworkRetransmitSetCompleted = false;
    //clearExtendedMeshNode();
    final LogSession logSession = Logger.newSession(context, null, device.getAddress(), device.getName());
    mBleMeshManager.setLogger(logSession);
    final BluetoothDevice bluetoothDevice = device.getDevice();
    initIsConnectedLiveData(connectToNetwork);
    mConnectionState.postValue("Connecting....");
    //Added a 1 second delay for connection, mostly to wait for a disconnection to complete before connecting.
    mHandler.postDelayed(() -> mBleMeshManager.connect(bluetoothDevice).retry(3, 200).enqueue(), 1000);
}
 
Example 2
Source File: BleProfileExpandableListActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onDeviceSelected(@NonNull final BluetoothDevice device, final String name) {
	final int titleId = getLoggerProfileTitle();
	if (titleId > 0) {
		logSession = Logger.newSession(getApplicationContext(), getString(titleId), device.getAddress(), name);
		// If nRF Logger is not installed we may want to use local logger
		if (logSession == null && getLocalAuthorityLogger() != null) {
			logSession = LocalLogSession.newSession(getApplicationContext(), getLocalAuthorityLogger(), device.getAddress(), name);
		}
	}
	deviceName = name;
	bleManager.setLogger(logSession);
	bleManager.connect(device)
			.useAutoConnect(shouldAutoConnect())
			.retry(3, 100)
			.enqueue();
}
 
Example 3
Source File: BleProfileServiceReadyActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onDeviceSelected(@NonNull final BluetoothDevice device, final String name) {
	final int titleId = getLoggerProfileTitle();
	if (titleId > 0) {
		logSession = Logger.newSession(getApplicationContext(), getString(titleId), device.getAddress(), name);
		// If nRF Logger is not installed we may want to use local logger
		if (logSession == null && getLocalAuthorityLogger() != null) {
			logSession = LocalLogSession.newSession(getApplicationContext(), getLocalAuthorityLogger(), device.getAddress(), name);
		}
	}
	bluetoothDevice = device;
	deviceName = name;

	// The device may not be in the range but the service will try to connect to it if it reach it
	Logger.d(logSession, "Creating service...");
	final Intent service = new Intent(this, getServiceClass());
	service.putExtra(BleProfileService.EXTRA_DEVICE_ADDRESS, device.getAddress());
	service.putExtra(BleProfileService.EXTRA_DEVICE_NAME, name);
	if (logSession != null)
		service.putExtra(BleProfileService.EXTRA_LOG_URI, logSession.getSessionUri());
	startService(service);
	Logger.d(logSession, "Binding to the service...");
	bindService(service, serviceConnection, 0);
}
 
Example 4
Source File: BleProfileActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onDeviceSelected(@NonNull final BluetoothDevice device, final String name) {
	final int titleId = getLoggerProfileTitle();
	if (titleId > 0) {
		logSession = Logger.newSession(getApplicationContext(), getString(titleId), device.getAddress(), name);
		// If nRF Logger is not installed we may want to use local logger
		if (logSession == null && getLocalAuthorityLogger() != null) {
			logSession = LocalLogSession.newSession(getApplicationContext(), getLocalAuthorityLogger(), device.getAddress(), name);
		}
	}
	deviceName = name;
	bleManager.setLogger(logSession);
	bleManager.connect(device)
			.useAutoConnect(shouldAutoConnect())
			.retry(3, 100)
			.enqueue();
}
 
Example 5
Source File: MainFragment.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates the new log session and makes the controls enabled.
 * If the nRF Logger application is not installed it will change the "Open in nRF Logger"
 * button to "Download nRF Logger".
 */
private void createLogSession(String key, String name) {
	mLogSession = Logger.newSession(requireContext(), key, name);

	// Enable buttons
	mField.setEnabled(true);
	mDropDown.setEnabled(true);
	mAddButton.setEnabled(true);
	mShowSessionInLoggerButton.setEnabled(true);
	mShowAllSessionsInLoggerButton.setEnabled(true);

	// The session is null if nRF Logger is not installed
	if (mLogSession == null) {
		Toast.makeText(getActivity(), R.string.error_no_nrf_logger, Toast.LENGTH_SHORT).show();
		mLogSession = LocalLogSession.newSession(requireContext(), MyLogContentProvider.AUTHORITY_URI, key, name);

		// The button will be used to download the nRF Logger
		mShowAllSessionsInLoggerButton.setText(R.string.action_download);
		mShowSessionInLoggerButton.setEnabled(false);
	}

	LoaderManager.getInstance(this).restartLoader(LOG_REQUEST_ID, null, this);
}
 
Example 6
Source File: BlinkyViewModel.java    From Android-nRF-Blinky with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Connect to the given peripheral.
 *
 * @param target the target device.
 */
public void connect(@NonNull final DiscoveredBluetoothDevice target) {
	// Prevent from calling again when called again (screen orientation changed).
	if (device == null) {
		device = target.getDevice();
		final LogSession logSession = Logger
				.newSession(getApplication(), null, target.getAddress(), target.getName());
		blinkyManager.setLogger(logSession);
		reconnect();
	}
}
 
Example 7
Source File: BleMulticonnectProfileServiceReadyActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onDeviceSelected(@NonNull final BluetoothDevice device, final String name) {
	final int titleId = getLoggerProfileTitle();
	ILogSession logSession = null;
	if (titleId > 0) {
		logSession = Logger.newSession(getApplicationContext(), getString(titleId), device.getAddress(), name);
		// If nRF Logger is not installed we may want to use local logger
		if (logSession == null && getLocalAuthorityLogger() != null) {
			logSession = LocalLogSession.newSession(getApplicationContext(), getLocalAuthorityLogger(), device.getAddress(), name);
		}
	}

	service.connect(device, logSession);
}
 
Example 8
Source File: nRFLoggerTree.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public nRFLoggerTree(final @NonNull Context context,
					 final @NonNull String key, final @NonNull String name) {
	this.session = Logger.newSession(context, null, key, name);
}
 
Example 9
Source File: nRFLoggerTree.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public nRFLoggerTree(final @NonNull Context context,
					 final @Nullable String profile,
					 final @NonNull String key, final @NonNull String name) {
	this.session = Logger.newSession(context, profile, key, name);
}
 
Example 10
Source File: nRFLoggerTree.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void newSession(final @NonNull String key, final @Nullable String name) {
	if (session != null) {
		session = Logger.newSession(session.getContext(), null, key, name);
	}
}
 
Example 11
Source File: nRFLoggerTree.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void newSession(final @Nullable String profile,
					   final @NonNull String key, final @Nullable String name) {
	if (session != null) {
		session = Logger.newSession(session.getContext(), profile, key, name);
	}
}