如何阻止对特定键码执行操作?

问题描述 投票:0回答:1

我制作了一个在带有条形码扫描仪的设备上运行的应用程序,现在我遇到一个问题,当用户读取“不接受的”条形码时,我会向用户显示alert并发出一些声音通知,问题是用户不关心它并仍然继续阅读其他代码。

因此,如果显示警告错误,我将以某种方式为KeyEvent 103和102禁用KeyCode(这些代码是激活扫描仪的按钮。)>

所以我会做这样的事情

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(event.getKeyCode() == 103 || event.getKeyCode() == 102) {
        if(Alerts.dialogError.isShowing()){
            // Here i should block the scanner
        }
    }
    Log.e("KeyPressed:", Integer.toString(keyCode));
    return false;
}

但是,实际上,如果调用那个KeyEvent中的一个,我应该如何“阻止”该动作?

这是我如何读取条形码

    private BroadcastReceiver myBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            if (Objects.equals(action, getResources().getString(R.string.activity_intent_filter_action))) {
                //  Received a barcode scan
                try {
                    displayScanResult(intent);
                } catch (Exception e) {
                    //  Catch if the UI does not exist when we receive the broadcast
                }
            }
        }
    };

 @SuppressLint("SetTextI18n")
    private void displayScanResult(Intent initiatingIntent)
    {

        String decodedData = initiatingIntent.getStringExtra(getResources().getString(R.string.datawedge_intent_key_data));

    // Putting decodedData in EditText and making all controls
    }

我制作了一个在带有条形码扫描仪的设备上运行的应用程序,现在我遇到一个问题,当用户读取“不被接受”的条形码时,我会向用户显示警报并发出一些声音通知,此问题...

android keyevent
1个回答
-1
投票

Android应用在沙盒中运行。您无权“禁用”某些键盘/扫描仪按钮。如果您要禁用其他读数,则应找到应用在何处/如何接受读数并将其阻止。我没有足够的信息来进一步帮助您。扫描仪自动填充为EditText吗?如果是这样,您可以使用.setEnabled(false)将其禁用。

© www.soinside.com 2019 - 2024. All rights reserved.