Android Studio - (zxing)W / CameraBase:连接到摄像机时出错:0

时间:2016-02-12 09:38:24

标签: android camera zxing

有一个类似的问题,但我没有找到解决方案。我正在使用Android Studio,这个错误发生在所有手机上。

我有一个使用相机进行扫描qrcode的应用程序。 应用程序像这样工作,首先当我打开应用程序相机工作顺利,它是扫描qrcode当它扫描qrcode我看到结果另一个活动后这一点有一个按钮扫描另一个qrcode这个按钮去预览活动在这指向相机看起来很黑。

完全注销是;

02-12 11:23:11.387 25722-25722/? E/Zygote: MountEmulatedStorage()
02-12 11:23:11.387 25722-25722/? E/Zygote: v2
02-12 11:23:11.387 25722-25722/? I/libpersona: KNOX_SDCARD checking this for 10459
02-12 11:23:11.387 25722-25722/? I/libpersona: KNOX_SDCARD not a persona
02-12 11:23:11.412 25722-25722/? I/SELinux: Function: selinux_compare_spd_ram, SPD-policy is existed. and_ver=SEPF_SM-N9000Q_5.0 ver=27
02-12 11:23:11.412 25722-25722/? I/SELinux: Function: selinux_compare_spd_ram , priority [1] , priority version is VE=SEPF_SM-N9000Q_5.0_0027
02-12 11:23:11.417 25722-25722/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
02-12 11:23:11.417 25722-25722/? I/art: Late-enabling -Xcheck:jni
02-12 11:23:11.452 25722-25722/? D/TimaKeyStoreProvider: TimaSignature is unavailable
02-12 11:23:11.452 25722-25722/? D/ActivityThread: Added TimaKeyStore provider
02-12 11:23:11.497 25722-25722/com.molekul.cografiisaretler D/ResourcesManager: creating new AssetManager and set to /data/app/com.molekul.cografiisaretler-1/base.apk
02-12 11:23:11.697 25722-25722/com.molekul.cografiisaretler V/BitmapFactory: DecodeImagePath(decodeResourceStream3) : res/drawable-xxhdpi-v4/abc_ic_ab_back_mtrl_am_alpha.png
02-12 11:23:11.717 25722-25722/com.molekul.cografiisaretler E/onCreate: onCreate
02-12 11:23:11.732 25722-25722/com.molekul.cografiisaretler D/Activity: performCreate Call secproduct feature valuefalse
02-12 11:23:11.732 25722-25722/com.molekul.cografiisaretler D/Activity: performCreate Call debug elastic valuetrue
02-12 11:23:11.787 25722-25798/com.molekul.cografiisaretler D/OpenGLRenderer: Render dirty regions requested: true
02-12 11:23:11.792 25722-25722/com.molekul.cografiisaretler D/Atlas: Validating map...
02-12 11:23:11.827 25722-25798/com.molekul.cografiisaretler I/OpenGLRenderer: Initialized EGL, version 1.4
02-12 11:23:11.837 25722-25798/com.molekul.cografiisaretler I/OpenGLRenderer: HWUI protection enabled for context ,  &this =0xaeb22088 ,&mEglDisplay = 1 , &mEglConfig = -1363909708 
02-12 11:23:11.857 25722-25798/com.molekul.cografiisaretler D/OpenGLRenderer: Enabling debug mode 0
02-12 11:23:12.572 25722-25722/com.molekul.cografiisaretler I/Choreographer: Skipped 45 frames!  The application may be doing too much work on its main thread.
02-12 11:23:13.137 25722-25722/com.molekul.cografiisaretler I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@1b9b925c time:14318576
02-12 11:23:16.747 25722-25722/com.molekul.cografiisaretler W/CameraBase: An error occurred while connecting to camera: 0
02-12 11:23:16.897 25722-25722/com.molekul.cografiisaretler I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@1b9b925c time:14322338
02-12 11:23:25.507 25722-25722/com.molekul.cografiisaretler E/SONUC: 18838813
02-12 11:23:25.507 25722-25722/com.molekul.cografiisaretler E/SONUC: UPC_E
02-12 11:23:25.507 25722-25722/com.molekul.cografiisaretler I/Timeline: Timeline: Activity_launch_request id:com.molekul.cografiisaretler time:14330949
02-12 11:23:25.547 25722-25722/com.molekul.cografiisaretler V/BitmapFactory: DecodeImagePath(decodeResourceStream3) : res/drawable-xxhdpi-v4/abc_ic_ab_back_mtrl_am_alpha.png
02-12 11:23:25.552 25722-25722/com.molekul.cografiisaretler E/onCreate: onCreate
02-12 11:23:25.577 25722-25722/com.molekul.cografiisaretler V/BitmapFactory: DecodeImagePath(decodeResourceStream3) : res/drawable/cross64.png
02-12 11:23:25.582 25722-25722/com.molekul.cografiisaretler D/Activity: performCreate Call secproduct feature valuefalse
02-12 11:23:25.582 25722-25722/com.molekul.cografiisaretler D/Activity: performCreate Call debug elastic valuetrue
02-12 11:23:25.592 25722-25722/com.molekul.cografiisaretler W/CameraBase: An error occurred while connecting to camera: 0
02-12 11:23:26.077 25722-25722/com.molekul.cografiisaretler I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@342580a7 time:14331515
02-12 11:23:26.087 25722-25722/com.molekul.cografiisaretler V/ActivityThread: updateVisibility : ActivityRecord{2d9f8043 token=android.os.BinderProxy@1b9b925c {com.molekul.cografiisaretler/com.molekul.cografiisaretler.MainActivity}} show : false
02-12 11:23:26.632 25722-25722/com.molekul.cografiisaretler D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
02-12 11:23:26.797 25722-25722/com.molekul.cografiisaretler I/Timeline: Timeline: Activity_launch_request id:com.molekul.cografiisaretler time:14332236
02-12 11:23:26.827 25722-25722/com.molekul.cografiisaretler E/onCreate: onCreate
02-12 11:23:26.827 25722-25722/com.molekul.cografiisaretler D/Activity: performCreate Call secproduct feature valuefalse
02-12 11:23:26.827 25722-25722/com.molekul.cografiisaretler D/Activity: performCreate Call debug elastic valuetrue
02-12 11:23:26.832 25722-25722/com.molekul.cografiisaretler W/CameraBase: An error occurred while connecting to camera: 0
02-12 11:23:26.962 25722-25798/com.molekul.cografiisaretler D/OpenGLRenderer: endAllStagingAnimators on 0x9c50ce00 (RippleDrawable) with handle 0xaeb17430
02-12 11:23:27.002 25722-25722/com.molekul.cografiisaretler I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@b3f84 time:14332441
02-12 11:23:27.387 25722-25722/com.molekul.cografiisaretler V/ActivityThread: updateVisibility : ActivityRecord{163c736d token=android.os.BinderProxy@342580a7 {com.molekul.cografiisaretler/com.molekul.cografiisaretler.informationActivity}} show : false

主要活动;

public class MainActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler{


    private ZXingScannerView mScannerView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.e("onCreate", "onCreate");
        mScannerView = new ZXingScannerView(this);
        setContentView(mScannerView);

    }

    @Override
    public void onResume() {
        super.onResume();

            mScannerView.setResultHandler(this);
            mScannerView.startCamera();

    }


    @Override
    public void handleResult(Result rawResult) {

        Log.e("SONUC", rawResult.getText());
        Log.e("SONUC", rawResult.getBarcodeFormat().toString());


        Intent intent = new Intent(MainActivity.this, informationActivity.class);
        startActivity(intent);

    }
}

信息活动;

public class informationActivity extends MainActivity {

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


    }
    public void yenidenTara(View view){

        Intent intent = new Intent(informationActivity.this, MainActivity.class);
        startActivity(intent);

    }

}

3 个答案:

答案 0 :(得分:1)

抱歉!我的错,这是MainActivity

 public class MainActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler{

        Integer response = 0 ;

        private ZXingScannerView mScannerView;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Log.e("onCreate", "onCreate");
            mScannerView = new ZXingScannerView(this);
            setContentView(mScannerView);

        }

        @Override
        public void onResume() {
            super.onResume();

            if(response == 1) {
                mScannerView = null;
                mScannerView = new ZXingScannerView(this);
                setContentView(mScannerView);
                response = 0;

            }

                mScannerView.setResultHandler(this);
                mScannerView.startCamera();

        }

        @Override
        public void onDestroy() {
            super.onDestroy();

            mScannerView = null;
            mScannerView.stopCamera();

        }


        @Override
        public void handleResult(Result rawResult) {

            Log.e("SONUC", rawResult.getText());
            Log.e("SONUC", rawResult.getBarcodeFormat().toString());


            Intent intent = new Intent(MainActivity.this, informationActivity.class);
            startActivity(intent);

        }
    }

AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.molekul.xx">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.molekul.xx.informationActivity"
            android:label="@string/app_name"
            android:parentActivityName=".MainActivity">
        </activity>

    </application>

</manifest>

答案 1 :(得分:1)

您应该确保您的应用请求/已启用W/CameraBase﹕ An error occurred while connecting to camera: 0

中提到的适当权限

在设置&gt;应用&gt; YourApp&gt;权限

中启用权限之前,我遇到了同样的问题

答案 2 :(得分:0)

@Override
    public void onDestroy() {
        super.onDestroy();

        mScannerView = null;
        mScannerView.stopCamera();

    }

首先使变量为null,然后尝试在其上调用方法。它可能会导致NullPointerException,并且也无法保证调用stopCamera()。因此,下一个相机硬件请求可能会卡住,因为之前的客户尚未发布相机。首先尝试在地方切换calles