首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >@SuppressLint("MissingPermission")使用它有害吗?

@SuppressLint("MissingPermission")使用它有害吗?
EN

Stack Overflow用户
提问于 2022-03-30 06:24:29
回答 1查看 238关注 0票数 0

我的代码给出了一个错误,覆盖了这个注释,修复了错误。这是一个健康的解决方案吗?给出错误的类与蓝牙相关。

代码语言:javascript
运行
复制
"Add permissions check" It gives an error when I do the suggestion.

错误:调用需要用户可能拒绝的权限:代码应该显式检查权限是否可用(使用checkPermission)或显式处理潜在的SecurityException

谢谢

我使用了@SuppressLint("MissingPermission"),但我不能相信

代码语言:javascript
运行
复制
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);
}
EN

回答 1

Stack Overflow用户

发布于 2022-03-30 06:36:12

AFAIK,为了避免出现MissingPermission错误,您必须检查函数中的权限。

现在,如果您完全确定该权限在调用此函数之前被检查过,那么使用@SuppressLint("MissingPermission")是可以的。另外,我要做的是,评论一下为什么你会抑制错误。行中的东西:@SuppressLint("MissingPermission") // permission must be checked before the call of the function!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71672424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档