no.nordicsemi.android.log.Logger Java Examples
The following examples show how to use
no.nordicsemi.android.log.Logger.
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: BleProfileServiceReadyActivity.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void onDeviceDisconnected(@NonNull final BluetoothDevice device) { connectButton.setText(R.string.action_connect); deviceNameView.setText(getDefaultDeviceName()); try { Logger.d(logSession, "Unbinding from the service..."); unbindService(serviceConnection); service = null; Logger.d(logSession, "Activity unbound from the service"); onServiceUnbound(); deviceName = null; bluetoothDevice = null; logSession = null; } catch (final IllegalArgumentException e) { // do nothing. This should never happen but does... } }
Example #2
Source File: nRFLoggerTree.java From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void log(@LogPriority final int priority, @Nullable final String tag, @NonNull final String message, @Nullable final Throwable t) { if (session == null) return; final int level = LogContract.Log.Level.fromPriority(priority); // Ignore t. Stack trace is already added to the message by prepareLog if (tag == null) { Logger.log(session, level, message); } else { Logger.log(session, level, "[" + tag + "] " + message); } }
Example #3
Source File: MainFragment.java From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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 #4
Source File: UARTService.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void onReceive(final Context context, final Intent intent) { final int source = intent.getIntExtra(EXTRA_SOURCE, SOURCE_NOTIFICATION); switch (source) { case SOURCE_NOTIFICATION: Logger.i(getLogSession(), "[Notification] Disconnect action pressed"); break; case SOURCE_WEARABLE: Logger.i(getLogSession(), "[WEAR] '" + Constants.ACTION_DISCONNECT + "' message received"); break; } if (isConnected()) getBinder().disconnect(); else stopSelf(); }
Example #5
Source File: UARTService.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Sends the given message to all connected wearables. If the path is equal to {@link Constants.UART#DEVICE_DISCONNECTED} the service will be stopped afterwards. * * @param path message path * @param message the message */ private void sendMessageToWearables(@NonNull final String path, @NonNull final String message) { if (googleApiClient.isConnected()) { new Thread(() -> { NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); for (Node node : nodes.getNodes()) { Logger.v(getLogSession(), "[WEAR] Sending message '" + path + "' to " + node.getDisplayName()); final MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), path, message.getBytes()).await(); if (result.getStatus().isSuccess()) { Logger.i(getLogSession(), "[WEAR] Message sent"); } else { Logger.w(getLogSession(), "[WEAR] Sending message failed: " + result.getStatus().getStatusMessage()); Log.w(TAG, "Failed to send " + path + " to " + node.getDisplayName()); } } if (Constants.UART.DEVICE_DISCONNECTED.equals(path)) stopService(); }).start(); } else { if (Constants.UART.DEVICE_DISCONNECTED.equals(path)) stopService(); } }
Example #6
Source File: BleProfileActivity.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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 #7
Source File: NrfMeshRepository.java From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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 #8
Source File: BleProfileServiceReadyActivity.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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 #9
Source File: BleProfileServiceReadyActivity.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void onStop() { super.onStop(); try { // We don't want to perform some operations (e.g. disable Battery Level notifications) // in the service if we are just rotating the screen. However, when the activity will // disappear, we may want to disable some device features to reduce the battery // consumption. if (service != null) service.setActivityIsChangingConfiguration(isChangingConfigurations()); unbindService(serviceConnection); service = null; Logger.d(logSession, "Activity unbound from the service"); onServiceUnbound(); deviceName = null; bluetoothDevice = null; logSession = null; } catch (final IllegalArgumentException e) { // do nothing, we were not connected to the sensor } }
Example #10
Source File: BleProfileServiceReadyActivity.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void onServiceDisconnected(final ComponentName name) { // Note: this method is called only when the service is killed by the system, // not when it stops itself or is stopped by the activity. // It will be called only when there is critically low memory, in practice never // when the activity is in foreground. Logger.d(logSession, "Activity disconnected from the service"); deviceNameView.setText(getDefaultDeviceName()); connectButton.setText(R.string.action_connect); service = null; deviceName = null; bluetoothDevice = null; logSession = null; onServiceUnbound(); }
Example #11
Source File: BleProfileServiceReadyActivity.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
@SuppressWarnings("unchecked") @Override public void onServiceConnected(final ComponentName name, final IBinder service) { final E bleService = BleProfileServiceReadyActivity.this.service = (E) service; bluetoothDevice = bleService.getBluetoothDevice(); logSession = bleService.getLogSession(); Logger.d(logSession, "Activity bound to the service"); onServiceBound(bleService); // Update UI deviceName = bleService.getDeviceName(); deviceNameView.setText(deviceName); connectButton.setText(R.string.action_disconnect); // And notify user if device is connected if (bleService.isConnected()) { onDeviceConnected(bluetoothDevice); } else { // If the device is not connected it means that either it is still connecting, // or the link was lost and service is trying to connect to it (autoConnect=true). onDeviceConnecting(bluetoothDevice); } }
Example #12
Source File: BleProfileService.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS)) throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key"); final Uri logUri = intent.getParcelableExtra(EXTRA_LOG_URI); logSession = Logger.openSession(getApplicationContext(), logUri); deviceName = intent.getStringExtra(EXTRA_DEVICE_NAME); Logger.i(logSession, "Service started"); final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); final String deviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS); bluetoothDevice = adapter.getRemoteDevice(deviceAddress); bleManager.setLogger(logSession); onServiceStarted(); bleManager.connect(bluetoothDevice) .useAutoConnect(shouldAutoConnect()) .retry(3, 100) .enqueue(); return START_REDELIVER_INTENT; }
Example #13
Source File: BleProfileExpandableListActivity.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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 #14
Source File: BleProfileService.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onDestroy() { super.onDestroy(); // Unregister broadcast receivers unregisterReceiver(bluetoothStateBroadcastReceiver); // shutdown the manager bleManager.close(); Logger.i(logSession, "Service destroyed"); bleManager = null; bluetoothDevice = null; deviceName = null; logSession = null; handler = null; }
Example #15
Source File: MainFragment.java From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { Uri uri = savedInstanceState.getParcelable(SIS_SESSION_URL); mLogSession = Logger.openSession(requireContext(), uri); mSelectedLevel = savedInstanceState.getInt(SIS_SELECTED_LEVEL); } }
Example #16
Source File: CSCService.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onReceive(final Context context, final Intent intent) { Logger.i(getLogSession(), "[Notification] Disconnect action pressed"); if (isConnected()) getBinder().disconnect(); else stopSelf(); }
Example #17
Source File: CGMService.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onReceive(final Context context, final Intent intent) { Logger.i(getLogSession(), "[Notification] Disconnect action pressed"); if (isConnected()) getBinder().disconnect(); else stopSelf(); }
Example #18
Source File: TemplateService.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onReceive(final Context context, final Intent intent) { Logger.i(getLogSession(), "[Notification] Disconnect action pressed"); if (isConnected()) getBinder().disconnect(); else stopSelf(); }
Example #19
Source File: UARTService.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onReceive(final Context context, final Intent intent) { final boolean hasMessage = intent.hasExtra(Intent.EXTRA_TEXT); if (hasMessage) { String message = intent.getStringExtra(Intent.EXTRA_TEXT); if (message == null) { final int intValue = intent.getIntExtra(Intent.EXTRA_TEXT, Integer.MIN_VALUE); // how big is the chance of such data? if (intValue != Integer.MIN_VALUE) message = String.valueOf(intValue); } if (message != null) { final int source = intent.getIntExtra(EXTRA_SOURCE, SOURCE_3RD_PARTY); switch (source) { case SOURCE_WEARABLE: Logger.i(getLogSession(), "[WEAR] '" + Constants.UART.COMMAND + "' message received with data: \"" + message + "\""); break; case SOURCE_3RD_PARTY: default: Logger.i(getLogSession(), "[Broadcast] " + ACTION_SEND + " broadcast received with data: \"" + message + "\""); break; } manager.send(message); return; } } // No data od incompatible type of EXTRA_TEXT if (!hasMessage) Logger.i(getLogSession(), "[Broadcast] " + ACTION_SEND + " broadcast received no data."); else Logger.i(getLogSession(), "[Broadcast] " + ACTION_SEND + " broadcast received incompatible data type. Only String and int are supported."); }
Example #20
Source File: BlinkyViewModel.java From Android-nRF-Blinky with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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 #21
Source File: RSCService.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onReceive(final Context context, final Intent intent) { Logger.i(getLogSession(), "[Notification] Disconnect action pressed"); if (isConnected()) getBinder().disconnect(); else stopSelf(); }
Example #22
Source File: HTService.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onReceive(final Context context, final Intent intent) { Logger.i(getLogSession(), "[Notification] Disconnect action pressed"); if (isConnected()) getBinder().disconnect(); else stopSelf(); }
Example #23
Source File: BleMulticonnectProfileServiceReadyActivity.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 #24
Source File: BleProfileServiceReadyActivity.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected final void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); ensureBLESupported(); if (!isBLEEnabled()) { showBLEDialog(); } // Restore the old log session if (savedInstanceState != null) { final Uri logUri = savedInstanceState.getParcelable(LOG_URI); logSession = Logger.openSession(getApplicationContext(), logUri); } // In onInitialize method a final class may register local broadcast receivers that will listen for events from the service onInitialize(savedInstanceState); // The onCreateView class should... create the view onCreateView(savedInstanceState); final Toolbar toolbar = findViewById(R.id.toolbar_actionbar); setSupportActionBar(toolbar); // Common nRF Toolbox view references are obtained here setUpView(); // View is ready to be used onViewCreated(savedInstanceState); LocalBroadcastManager.getInstance(this).registerReceiver(commonBroadcastReceiver, makeIntentFilter()); }
Example #25
Source File: nRFLoggerTree.java From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License | 4 votes |
public nRFLoggerTree(final @NonNull Context context, final @Nullable Uri uri) { this.session = Logger.openSession(context, uri); }
Example #26
Source File: nRFLoggerTree.java From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void newSession(final @NonNull String key, final @Nullable String name) { if (session != null) { session = Logger.newSession(session.getContext(), null, key, name); } }
Example #27
Source File: nRFLoggerTree.java From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License | 4 votes |
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); } }
Example #28
Source File: LoggableBleManager.java From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void log(final int priority, @NonNull final String message) { Logger.log(mLogSession, LogContract.Log.Level.fromPriority(priority), message); Log.println(priority, "BleManager", message); }
Example #29
Source File: nRFLoggerTree.java From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License | 4 votes |
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 #30
Source File: nRFLoggerTree.java From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License | 4 votes |
public nRFLoggerTree(final @NonNull Context context, final @NonNull String key, final @NonNull String name) { this.session = Logger.newSession(context, null, key, name); }