'@SuppressLint("MissingPermission") using is it harmful?
My code was giving an error Overwriting this annotation fixed the error. Is this a healthy solution? The class giving the error is related to bluetooth.
"Add permissions check" It gives an error when I do the suggestion.
Error: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException
Thanks
I used @SuppressLint("MissingPermission") but I couldn't trust
public synchronized void connected(BluetoothSocket socket, BluetoothDevice
device, final String socketType) {
// Cancel the thread that completed the connection
if (mConnectThread != null) {mConnectThread.cancel(); mConnectThread = null;}
// Cancel any thread currently running a connection
if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;}
// Cancel the accept thread because we only want to connect to one device
if (mSecureAcceptThread != null) {
mSecureAcceptThread.cancel();
mSecureAcceptThread = null;
}
// Start the thread to manage the connection and perform transmissions
mConnectedThread = new ConnectedThread(socket, socketType);
mConnectedThread.start();
// Send the name of the connected device back to the UI Activity
Message msg = mHandler.obtainMessage(BluetoothState.MESSAGE_DEVICE_NAME);
Bundle bundle = new Bundle();
bundle.putString(BluetoothState.DEVICE_NAME, device.getName());
bundle.putString(BluetoothState.DEVICE_ADDRESS, device.getAddress());
msg.setData(bundle);
mHandler.sendMessage(msg);
setState(BluetoothState.STATE_CONNECTED);
}
Solution 1:[1]
AFAIK, in order for MissingPermission error not to appear, you would have to check for the permission within the function.
Now, if you are absolutely certain, that the permission is, and will be, getting checked before the call of this function, it is OK to use @SuppressLint("MissingPermission"). What I would additionally do, is put a comment as to why you suppressed the error. Something in the line of: @SuppressLint("MissingPermission") // permission must be checked before the call of the function!.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Primož Ivan?i? |
