I / HwPointEventFilter:由于没有配置,因此不支持AFT

如何解决I / HwPointEventFilter:由于没有配置,因此不支持AFT

我在开发文本扫描应用程序时遇到问题,那就是当我试图快速使用已冻结在我的华为手机上的相机扫描/识别文本时。但它可以在其他Android设备上正常工作 为什么?

这是logcat Msg 省略时间和项目包名称

I/CameraManagerGlobal: Connecting to camera service
I/HwPointEventFilter: do not support AFT because of no config
I/SendBroadcastPermission: action:huawei.intent.action.APS_TOUCH_ACTION_DOWN,mPermissionType:0
I/SendBroadcastPermission: action:huawei.intent.action.APS_TOUCH_ACTION_UP,mPermissionType:0

清单文件

  <activity
        android:name=".CameraActivity"
        android:screenOrientation="portrait">
 </activity>

这是我的CameraActivity.java

忽略导入和包裹名称

public class CameraActivity extends AppCompatActivity implements View.OnClickListener {
    private CameraKitView cameraKitView;
    private ImageView btn_capture,btn_flashlight;
    private String flashMode = "";
    private AlertDialog dialog;
    private Context mContext;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        Objects.requireNonNull(getSupportActionBar()).hide();
        mContext = this;

        cameraKitView = findViewById(R.id.camera);
        btn_capture = findViewById(R.id.btn_capture);
        btn_flashlight = findViewById(R.id.btn_flashlight);
        cameraKitView.requestPermissions(this);


        flashMode = SharedHelper.getKey(this,"flashMode");

        if (flashMode.isEmpty() || flashMode.equals("off")) {
            flashMode = "off";
            flash("off");
        }

        flash(flashMode);

        btn_flashlight.setOnClickListener(this);
        btn_capture.setOnClickListener(this);


        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(false);
        builder.setTitle(R.string.processing);
        builder.setView(R.layout.loading_dialoag);
        dialog = builder.create();


    }


    public void flash(String mode) {
        switch (mode) {
            case "off":
                cameraKitView.setFlash(CameraKit.FLASH_OFF);
                btn_flashlight.setImageDrawable(getDrawable(R.drawable.ic_flash_off_white_24dp));
                break;
            case "on":
                cameraKitView.setFlash(CameraKit.FLASH_ON);
                btn_flashlight.setImageDrawable(getDrawable(R.drawable.ic_flash_on_white_24dp));
                break;
            case "auto":
                cameraKitView.setFlash(CameraKit.FLASH_AUTO);
                btn_flashlight.setImageDrawable(getDrawable(R.drawable.ic_flash_auto_white_24dp));
                break;
        }

    }


    @Override
    protected void onStart() {
        super.onStart();
        cameraKitView.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
        cameraKitView.onResume();
    }

    @Override
    protected void onPause() {
        cameraKitView.onPause();
        super.onPause();
    }

    @Override
    protected void onStop() {
        cameraKitView.onStop();
        super.onStop();
    }

    @Override
    public void onRequestPermissionsResult(int requestCode,String[] permissions,int[] grantResults) {
        super.onRequestPermissionsResult(requestCode,permissions,grantResults);
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_DENIED) {
            Toast.makeText(this,"You must allow permission to use the camera",Toast.LENGTH_SHORT).show();
            finish();
        }

        cameraKitView.onRequestPermissionsResult(requestCode,grantResults);
    }


    @Override
    public void onClick(View view) {
        if (view == btn_capture) {
            cameraKitView.captureImage(new CameraKitView.ImageCallback() {
                @Override
                public void onImage(CameraKitView cameraKitView,final byte[] capturedImage) {
                    // capturedImage contains the image from the CameraKitView.
                    captureSound();
                    BitmapFactory.Options opts = new BitmapFactory.Options();
                    Bitmap bitmap = BitmapFactory.decodeByteArray(capturedImage,capturedImage.length,opts);
                    FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
                    imageProcessor(image);
                    dialog.show();
                    cameraKitView.onStop();


                }
            });

        } else if (view == btn_flashlight) {
            switch (flashMode) {
                case "off":
                    flashMode = "on";
                    flash("on");
                    SharedHelper.putKey(this,"flashMode","on");
                    break;
                case "on":
                    flashMode = "auto";
                    flash("auto");
                    SharedHelper.putKey(this,"auto");
                    break;
                case "auto":
                    flashMode = "off";
                    flash("off");
                    SharedHelper.putKey(this,"off");
                    break;
            }


        }
    }

    public void imageProcessor(FirebaseVisionImage image) {
        FirebaseVisionDocumentTextRecognizer detector = FirebaseVision.getInstance()
                .getCloudDocumentTextRecognizer();

        detector.processImage(image)
                .addOnSuccessListener(new OnSuccessListener<FirebaseVisionDocumentText>() {
                    @Override
                    public void onSuccess(FirebaseVisionDocumentText result) {
                        dialog.dismiss();
                        Intent intent = new Intent(CameraActivity.this,TextActivity.class);
                        intent.putExtra("result",result.getText());
                        startActivity(intent);
                        overridePendingTransition(R.anim.push_left_in,R.anim.push_left_out);
                        finish();

                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        dialog.dismiss();
                        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                        builder.setTitle("Processing Failed");
                        builder.setMessage(e.getLocalizedMessage());

                        builder.setPositiveButton(R.string.ok,new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface,int i) {
                                cameraKitView.onStart();
                                cameraKitView.onResume();
                            }
                        }).show();
                    }
                });

    }

    public void captureSound(){
        AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        switch( audio.getRingerMode() ){
            case AudioManager.RINGER_MODE_NORMAL:
                MediaActionSound sound = new MediaActionSound();
                sound.play(MediaActionSound.SHUTTER_CLICK);
                break;
            case AudioManager.RINGER_MODE_SILENT:
                break;
            case AudioManager.RINGER_MODE_VIBRATE:
                break;
        }
    }
}

解决方法

我试图运行您在华为手机上提供的代码。首次启动该应用程序时,相机没有响应,我认为这是因为该应用程序没有访问相机的权限。

根据Camera Engine官方网站上的参考文档,我认为您不需要调用 cameraKitView.requestPermissions(this)。删除调用此方法的行后,该应用程序在首次启动后便可以正常运行,并且能够动态地申请摄像头许可。


此外,我注意到您集成了Firebase的ML Kit。根据{{​​3}}, com.google.firebase:firebase-ml-vision:24.1.0 需要Google Play。否则,该套件将无法正常工作。

由于Google禁令后推出的华为手机无法使用GMS,因此您的手机可能不支持Google Play。这就是您的应用无法正常运行的原因。您可以集成HUAWEI ML Kit,它可以在所有Android设备上正常运行。 HUAWEI ML Kit支持文本识别和文档识别等功能。有关详细信息,请参阅Firebase's reference documents。建议您使用Integration Documents,它可以帮助您快速添加HMS + GMS适配层代码并升级逻辑代码以支持GMS和HMS。

我对代码进行了以下更改,以供您参考:修改如下:

  1. 注释以下行以解决相机无响应的问题。 cameraKitView.requestPermissions(this);
  2. 将配置 firebase-ml-vision 的行替换为配置HUAWEI ML Kit的行,以便您的应用可以支持文本识别。
public class CameraActivity extends AppCompatActivity implements View.OnClickListener {
    private CameraKitView cameraKitView;
    private ImageView btn_capture,btn_flashlight;
    private String flashMode = "";
    private AlertDialog dialog;
    private Context mContext;
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        Objects.requireNonNull(getSupportActionBar()).hide();
        mContext = this;
        
        cameraKitView = findViewById(R.id.camera);
        btn_capture = findViewById(R.id.btn_capture);
        btn_flashlight = findViewById(R.id.btn_flashlight);
        // cameraKitView.requestPermissions(this);
        
        
        flashMode = SharedHelper.getKey(this,"flashMode");
        
        if (flashMode.isEmpty() || flashMode.equals("off")) {
            flashMode = "off";
            flash("off");
        }

        flash(flashMode);

        btn_flashlight.setOnClickListener(this);
        btn_capture.setOnClickListener(this);


        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(false);
        builder.setTitle(R.string.processing);
        builder.setView(R.layout.loading_dialoag);
        dialog = builder.create();
        
        
    }
    
    
    public void flash(String mode) {
        switch (mode) {
            case "off":
                cameraKitView.setFlash(CameraKit.FLASH_OFF);
                btn_flashlight.setImageDrawable(getDrawable(R.drawable.flashlight_off));
                break;
            case "on":
                cameraKitView.setFlash(CameraKit.FLASH_ON);
                btn_flashlight.setImageDrawable(getDrawable(R.drawable.flashlight_on));
                break;
            case "auto":
                cameraKitView.setFlash(CameraKit.FLASH_AUTO);
                btn_flashlight.setImageDrawable(getDrawable(R.drawable.flashlight_auto));
                break;
        }
        
    }
    
    
    @Override
    protected void onStart() {
        super.onStart();
        cameraKitView.onStart();
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        cameraKitView.onResume();
    }
    
    @Override
    protected void onPause() {
        cameraKitView.onPause();
        super.onPause();
    }
    
    @Override
    protected void onStop() {
        cameraKitView.onStop();
        super.onStop();
    }
    
    @Override
    public void onRequestPermissionsResult(int requestCode,String[] permissions,int[] grantResults) {
        super.onRequestPermissionsResult(requestCode,permissions,grantResults);
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_DENIED) {
            Toast.makeText(this,"You must allow permission to use the camera",Toast.LENGTH_SHORT).show();
            finish();
        }
        
        cameraKitView.onRequestPermissionsResult(requestCode,grantResults);
    }
    
    
    @Override
    public void onClick(View view) {
        if (view == btn_capture) {
            cameraKitView.captureImage(new CameraKitView.ImageCallback() {
                @Override
                public void onImage(CameraKitView cameraKitView,final byte[] capturedImage) {
                    // capturedImage contains the image from the CameraKitView.
                    captureSound();
                    BitmapFactory.Options opts = new BitmapFactory.Options();
                    Bitmap bitmap = BitmapFactory.decodeByteArray(capturedImage,capturedImage.length,opts);
                    // FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
                    MLFrame frame = MLFrame.fromBitmap(bitmap);
                    imageProcessor(frame);
                    dialog.show();
                    cameraKitView.onStop();
                    
                    
                }
            });
            
        } else if (view == btn_flashlight) {
            switch (flashMode) {
                case "off":
                    flashMode = "on";
                    flash("on");
                    SharedHelper.putKey(this,"flashMode","on");
                    break;
                case "on":
                    flashMode = "auto";
                    flash("auto");
                    SharedHelper.putKey(this,"auto");
                    break;
                case "auto":
                    flashMode = "off";
                    flash("off");
                    SharedHelper.putKey(this,"off");
                    break;
            }
            
            
        }
    }
    
    private void imageProcessor(MLFrame frame) {
        MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer();
        
        Task<MLText> task = analyzer.asyncAnalyseFrame(frame);
        task.addOnSuccessListener(new OnSuccessListener<MLText>() {
            @Override
            public void onSuccess(MLText text) {
                Toast.makeText(CameraActivity.this,text.getStringValue(),Toast.LENGTH_SHORT).show();
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(Exception e) {
                Toast.makeText(CameraActivity.this,e.getMessage(),Toast.LENGTH_SHORT).show();
            }
        });
    }
    
    public void captureSound(){
        AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        switch( audio.getRingerMode() ){
            case AudioManager.RINGER_MODE_NORMAL:
                MediaActionSound sound = new MediaActionSound();
                sound.play(MediaActionSound.SHUTTER_CLICK);
                break;
            case AudioManager.RINGER_MODE_SILENT:
                break;
            case AudioManager.RINGER_MODE_VIBRATE:
                break;
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>

-<androidx.constraintlayout.widget.ConstraintLayout tools:context=".CameraActivity" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android">

<com.camerakit.CameraKitView android:layout_height="0dp" android:layout_width="match_parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toTopOf="@id/btn_capture" app:camera_permissions="camera" app:camera_focus="continuous" app:camera_flash="auto" app:camera_facing="back" android:keepScreenOn="true" android:adjustViewBounds="true" android:id="@+id/camera"> </com.camerakit.CameraKitView>

<ImageView android:layout_height="50dp" android:layout_width="match_parent" app:layout_constraintBottom_toTopOf="@id/btn_flashlight" android:id="@+id/btn_capture" android:src="@drawable/take_photos"/>

<ImageView android:layout_height="50dp" android:layout_width="match_parent" android:id="@+id/btn_flashlight" android:src="@drawable/flashlight_off" app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-