简体   繁体   English

在我的应用中实施QR码扫描仪

[英]Implement a QR code Scanner to my app

I'm working on an android app using web server to store users and data. 我正在使用网络服务器来存储用户和数据的android应用程序上工作。 I have already generated a Qr code for each user with PHP. 我已经使用PHP为每个用户生成了一个Qr代码。 I need to scan that Qr Code to make users login. 我需要扫描该二维码以使用户登录。 I have already tried to implement Zxing. 我已经尝试实现Zxing。

This is the function I use to call the ZXing QR code. 这是我用来调用ZXing QR码的功能。

 btnLogin.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {

            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
            startActivityForResult(intent,0);


        }

    });

This is my manifest file 这是我的清单文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dahmani.javagose.cameratest" >

<uses-feature android:name="android.hardware.Camera" />

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

<application
    android:name=".app.AppController"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <activity android:name=".LoginActivity"
        android:launchMode="singleTop"
        android:windowSoftInputMode="adjustPan"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar" >
    </activity>


    <activity
        android:name=".PhotoInfoActivity"
        android:label="@string/title_activity_photo_info"
        android:theme="@style/AppTheme.NoActionBar" >
    </activity>


</application>

and this my build.gradle.app 这是我的build.gradle.app

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.dahmani.javagose.cameratest"
    minSdkVersion 9
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    debug {
        debuggable true
    }
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:23.1.1'
  compile 'com.android.support:design:23.1.1'
  compile 'com.google.android.gms:play-services:8.4.0'
  compile 'com.mcxiaoke.volley:library-aar:1.0.0'
  compile 'me.dm7.barcodescanner:zxing:1.8.4'

}

However, when I click the login btn , the app crashes. 但是,当我单击登录btn时,应用程序崩溃了。

and this what shows android monitor 这显示了Android监视器

 03-07 16:10:15.293 18916-18916/? E/AndroidRuntime: FATAL EXCEPTION: main
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime: Process: com.dahmani.javagose.cameratest, PID: 18916
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN (has extras) }
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1727)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1511)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at android.app.Activity.startActivityForResult(Activity.java:3424)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at android.app.Activity.startActivityForResult(Activity.java:3385)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at com.dahmani.javagose.cameratest.LoginActivity$1.onClick(LoginActivity.java:81)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at android.view.View.performClick(View.java:4499)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:18571)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:733)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:136)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5021)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
03-07 16:10:15.293 18916-18916/? E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)

The problem might be that you don't have zxing scanner app. 问题可能是您没有zxing扫描仪应用程序。 The standard library doesn't offer you and embedded way of scanning QR codes, at least none that I'm aware of. 标准库不为您提供扫描QR码的嵌入式方法,至少我不知道。

So, you have 2 ways of doing it. 因此,您有2种方法可以执行此操作。 Install zxing scanner app (or request user to install it if it does not exist on the phone, redirecting him/her to google play). 安装zxing扫描仪应用程序(或如果手机上不存在该应用程序,则要求用户安装它,将其重定向至Google Play)。 This is the ugly way. 这是丑陋的方式。

Or, you can use another library: 或者,您可以使用另一个库:

embedded zxing 嵌入式zxing

I used it for embedding scanner into my app. 我用它来将扫描仪嵌入到我的应用程序中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 很难将 zxing 二维码扫描仪集成到我的 Android 应用程序中 - Difficulty intergrating zxing QR code scanner into my Android app 如何在Android中以人像模式在Fragment中实现QR码扫描仪? - How to implement QR code scanner in Fragment in portrait mode in android? 二维码和扫描仪,Android? - Qr Code and scanner, Android ? 使用Qr扫描仪扫描无效的字符串时,我的应用程序崩溃 - My app is crashing when scan invalid String by using Qr scanner Android Studio QR码扫描仪Zxing。 如何在我的应用程序中打开QR码扫描的结果(URL链接)? - Android Studio QR Code Scanner Zxing. How can I open the Result of the QR Code scan (URL Link) within my Application? 例如,如何将 QR 码扫描仪应用到我的 webview 应用程序,然后将 QR 码放入 Google 搜索引擎 - How can I apply the QR Code scanner to my webview application and then put the QR Code in the Google search engine, for example QR码扫描仪的URL结果 - URL Result from QR Code Scanner QR码扫描仪-空格字符问题 - QR Code Scanner - space character problem Android QR 码扫描仪相机未在片段中打开 - Android QR Code Scanner camera not opening in Fragment 如何制作像最近包含的Paytm android应用中的QR码扫描仪? - How to make a QR code scanner like in Paytm android app which was included recently?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM