Java detector.isOperational()在android上始终为false

Java detector.isOperational()在android上始终为false,java,android,barcode,Java,Android,Barcode,我正在使用新的google plays服务:条形码检测器,对于此porposue,我将遵循本教程: 但当我在我的真实设备(华硕Nexus 7)上运行应用程序时,应用程序的文本视图总是显示“无法设置探测器”,我不知道如何使其工作>不带+字符

我正在使用新的google plays服务:条形码检测器,对于此porposue,我将遵循本教程:

但当我在我的真实设备(华硕Nexus 7)上运行应用程序时,应用程序的文本视图总是显示“无法设置探测器”,我不知道如何使其工作><

下面是一些用于快速调试的代码:

public class DecoderBar extends Activity implements View.OnClickListener{

private TextView  txt;
private ImageView img;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_decoder);

    Button b = (Button) findViewById(R.id.button);
    txt = (TextView) findViewById(R.id.txtContent);
    img = (ImageView) findViewById(R.id.imgview);

    b.setOnClickListener(this);
}

// [...]

@Override
public void onClick(View v) {

    Bitmap myBitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.popi);
    img.setImageBitmap(myBitmap);

    BarcodeDetector detector = new BarcodeDetector.Builder(getApplicationContext())
            .setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE)
            .build();

    if(!detector.isOperational()){
        // Always show this message, so, never is operational!
        txt.setText("Could not set up the detector!");
        return;
    }

    Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
    SparseArray<Barcode> barcodes = detector.detect(frame);

    Barcode thisCode = barcodes.valueAt(0);
    txt.setText(thisCode.rawValue);
}
}
公共类DecoderBar扩展活动实现View.OnClickListener{
私有文本视图;
私有图像视图img;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.layout\u解码器);
按钮b=(按钮)findViewById(R.id.Button);
txt=(TextView)findViewById(R.id.txtContent);
img=(ImageView)findViewById(R.id.imgview);
b、 setOnClickListener(此);
}
// [...]
@凌驾
公共void onClick(视图v){
位图myBitmap=BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.popi);
设置图像位图(myBitmap);
BarcodeDetector=新的BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(条形码.数据|矩阵|条形码.二维码)
.build();
如果(!detector.isOperational()){
//始终显示此消息,因此,永不运行!
txt.setText(“无法设置检测器!”);
返回;
}
Frame Frame=new Frame.Builder().setBitmap(myBitmap.build();
SparseArray条码=检测器。检测(帧);
条形码thisCode=条形码。值位于(0);
txt.setText(thisCode.rawValue);
}
}

要使用API,必须连接互联网,我连接了ADSL,但没有解析DNS。解决了这个问题,使我的应用程序可以正常工作。看起来,在每台设备上首次使用条形码检测器时,谷歌Play服务会进行一些下载。以下是链接:

以下是摘录:

首次安装使用条形码和/或face API的应用程序 在设备上,GMS将向设备下载一个库,以便 做条形码和人脸检测。通常这是由安装程序完成的 在应用程序首次运行之前


有时,在应用程序首次运行时下载检测器依赖项,而不是在应用程序安装时下载。我也面临着同样的问题,问题是你的网络连接很弱,或者你没有足够的存储空间来下载,比如说总空间的10%,虽然它不占用那么多空间,但是从Google Play服务下载确实需要大量的存储空间,别忘了清除缓存(简单检查尝试更新playstore中的任何应用程序)。有关更多信息,请参阅此项。

我现在遇到了此问题。您无法更新Google Play服务。在我使用了与教程中相同的服务后,它就可以工作了


编译“com.google.android.gms:play services:7.8+”

检查您的存储空间!确保存储空间超过10%

这解决了我的问题,我也在这里回答了


您不能忘记这一点:

将此添加到您的
AndroidManifest.xml

<application
   android:allowBackup="true"
   android:icon="@mipmap/ic_launcher"
   android:label="@string/app_name"
   android:roundIcon="@mipmap/ic_launcher_round"
   android:supportsRtl="true"
   android:theme="@style/AppTheme">


<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
<meta-data
    android:name="com.google.android.gms.vision.DEPENDENCIES"
    android:value="ocr"/>

以下是我的案例。 我使用BarcodeDetector从导入的图像中解码二维码。在我的4台测试设备上,它工作正常。在一台设备上,没有从位图中读取任何内容。我认为这可能与android 5.0不兼容,但事实并非如此。经过数小时的调查,我终于注意到
detector.isOperational();
返回false。原因是:

第一次在设备上安装使用条形码和/或人脸API的应用程序时,GMS将下载一个库到设备上,以便进行条形码和人脸检测。通常在应用程序首次运行之前由安装程序完成


我在测试设备上关闭了wi-fi。在打开它并重新启动应用程序后,检测器开始运行并开始解码位图。

我也遇到了这个问题-Nexus 4和5.1.1 CyanogenMod 12.1以及Google Play Services 8.3.0。互联网连接没有问题(工作正常且快速),可用存储也没有,但仍然得到了等操作的always false.try with compile'com.google.android.gms:play services:7.8.0'->不带+字符