精华内容
参与话题
问答
  • Android扫描二维码

    2020-06-21 14:27:32
    Android工程, 原生代码编写的二维码扫描,内包含使用的jar包。方便快捷,合适进行二次开发。扫码得到内容弹框出来显示。此功能可根据自己需求更改
  • android扫描二维码

    2016-12-13 15:46:13
    android扫描二维码
  • Android 扫描二维码

    2018-11-07 19:10:24
    首先布局 xml <Button android:id="@+id/btn&... android:layout_width=&... android:layout_height=&... android:text=&...打开二维码扫描界面"/>

    在这里插入图片描述首先布局

    xml

       <Button android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="打开二维码扫描界面"/>
    

    MainActivity

    public class MainActivity extends AppCompatActivity {

    private Button mBtn;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mBtn = findViewById(R.id.btn);
        mBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,CaptureActivity.class);
                startActivityForResult(intent,1);
            }
        });
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /**
         * 处理二维码的扫描结果
         */
        if (requestCode == 1){
            //处理扫描结果(在界面上显示)
            if (data != null){
                Bundle bundle = data.getExtras();
                if (bundle == null){
                    return;
                }
                if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS){
                    String result = bundle.getString(CodeUtils.RESULT_STRING);
                    Toast.makeText(this,"解析结果"+result,Toast.LENGTH_LONG).show();
                }else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED){
                    Toast.makeText(this,"解析二维码失败",Toast.LENGTH_LONG).show();
                }
            }
        }
    }
    

    }
    创建一个类

    MyApplication

    public void onCreate() {
        super.onCreate();
        ZXingLibrary.initDisplayOpinion(this);
    }
    

    在build里边写入下边

     configurations.all {
            resolutionStrategy.eachDependency { DependencyResolveDetails details ->
                def requested = details.requested
                if (requested.group == 'com.android.support') {
                    if (!requested.name.startsWith("multidex")) {
                        details.useVersion '27.1.1' //这里改为你项目使用的版本即可
                    }
                }
            }
        }
    

    导入依赖

     implementation 'cn.yipianfengye.android:zxing-library:2.2'
    

    写入权限

        <uses-permission android:name="android.permission.CAMERA" />
        <uses-permission android:name="android.permission.FLASHLIGHT" />
        <uses-feature android:name="android.hardware.camera" />
        <uses-feature android:name="android.hardware.camera.autofocus" />
        <uses-permission android:name="android.permission.VIBRATE" />
        <uses-permission android:name="android.permission.WAKE_LOCK" />
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.INTERNET" />
        //千万要记得Application 写入这句话  否则 嘿嘿O(∩_∩)   让你找半天Bug
        android:name=".MyApplication"
    
    展开全文
  • android 扫描二维码

    2017-05-10 09:30:48
    http://blog.csdn.net/qq_28057541/article/details/52034988 http://blog.csdn.net/sankoshine/article/details/50823238?skin=ink gradle文件引用 dependencies { compile 'com.google.zxing:core:3.3.0'

    http://blog.csdn.net/qq_28057541/article/details/52034988

    http://blog.csdn.net/sankoshine/article/details/50823238?skin=ink

    扫描框自定义仿微信样式http://download.csdn.net/detail/z_zt_t/9659802

    gradle文件引用

    dependencies {
        compile 'com.google.zxing:core:3.3.0'
        compile 'com.journeyapps:zxing-android-embedded:3.3.0'
    }
    

    扫描返回结果

    @Override
        // 通过 onActivityResult的方法获取 扫描回来的 值   扫描二维码返回
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            try {
                IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode,resultCode,data);
                if(intentResult != null) {
                    if(intentResult.getContents() != null) {
                        // ScanResult 为 获取到的字符串
                        String ScanResult = intentResult.getContents();
                        HLog.v(TAG,"ScanResult",ScanResult);
                        //扫描二维码
                        if(!TextUtils.isEmpty(ScanResult)){
                            isScanHandler.removeMessages(0);
                            HkApplication.toWebView(ScanResult,MainActivity.this);
                        }else{
                            
                        }
    
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }



    跳转到扫描二维码activity

    // 你也可以使用简单的扫描功能,但是一般扫描的样式和行为都是可以自定义的,这里就写关于自定义的代码了
        // 你可以把这个方法作为一个点击事件
        public void customScan(){
            new IntentIntegrator(this)
                    .setOrientationLocked(false)
                    .setCaptureActivity(ZxingScanActivity.class) // 设置自定义的activity是CustomActivity
                    .initiateScan(); // 初始化扫描
            isScanHandler.sendEmptyMessageDelayed(0,30000);//30秒未扫描到,提示
        }

    扫描二维码activity

    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.PersistableBundle;
    import android.view.KeyEvent;
    import android.view.View;
    import android.view.Window;
    import android.widget.TextView;
    
    import com.journeyapps.barcodescanner.CaptureManager;
    import com.journeyapps.barcodescanner.DecoratedBarcodeView;
    
    /**
     * 扫描二维码
     * Created by ypp on 2017/4/8.
     */
    
    public class ZxingScanActivity extends Activity implements View.OnClickListener{
        private final String TAG="ZxingScanActivity";
        private CaptureManager captureManager;//扫描
        private DecoratedBarcodeView dbv_custom;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.activity_zxing_scan);
            dbv_custom=(DecoratedBarcodeView)findViewById(R.id.dbv_custom);
    
            //重要代码,初始化捕获
            captureManager = new CaptureManager(this,dbv_custom);
            captureManager.initializeFromIntent(getIntent(),savedInstanceState);
            captureManager.decode();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            },29000);
        }
    
        @Override
        public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
            super.onSaveInstanceState(outState, outPersistentState);
            captureManager.onSaveInstanceState(outState);
        }
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            return dbv_custom.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
        }
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.left_btn:
                    finish();
                    break;
            }
        }
    
    }
    
    布局文件

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:background="@color/black">
        <RelativeLayout
            android:id="@+id/title_layout"
            style="@style/title_bar_layout_style"
            android:background="@drawable/title_bar_bg">
    
    
            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="@string/scan_for_awhile"
                android:textColor="@color/white"
                android:textSize="18sp" />
    
            <TextView
                android:id="@+id/left_btn"
                style="@style/title_back_btn_style"
                android:layout_width="55dip"
                android:layout_height="match_parent" />
        </RelativeLayout>
        <SurfaceView
            android:id="@+id/surfaceview"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_below="@id/title_layout"/>
        <!-- 这个控件就是扫描的窗口了 -->
        <com.journeyapps.barcodescanner.DecoratedBarcodeView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/dbv_custom"
            app:zxing_framing_rect_width="200dp"
            app:zxing_framing_rect_height="200dp"
            app:zxing_preview_scaling_strategy="fitXY"
            app:zxing_use_texture_view="true"
            android:layout_centerInParent="true"
            android:layout_below="@id/title_layout"/>
    </RelativeLayout>


    展开全文
  • 。。。。。。。Android扫描二维码及生成二维码Demo
  • Android 扫描二维码demo

    2018-11-12 15:15:23
    这个代码包,非常简便集成了Android客户端扫描二维码功能
  • android 扫描二维码程序代码 可将扫描结果存到手机中的 名为Barcode文件夹下面的BS.txt文件中
  • 使用zxing扫描二维码时会出现中文乱码问题,找很久发现是zxing不支持gbk编码,所以把zxing.jar中的解码类做下修改,现在将修改后的java文件提供给大家。
  • 打开相机,扫描二维码 1.在用Android 7.0版本时,调用相机拍照出现了异常 FileUriExposedException,就是在传递uri时出错 Android 7.0后又修改了文件权限,可以使用FileProvider解决 详件见 ...

    一。打开相机,扫描二维码

    1.在用Android 7.0版本时,调用相机拍照出现了异常 FileUriExposedException,就是在传递uri时出错 Android 7.0后又修改了文件权限,可以使用FileProvider解决 详件见 http://blog.csdn.net/qq_38208201/article/details/76530312

    展开全文
  • 通过Paint画笔自己绘制了二维码扫描框、仿微信扫面二维码、界面更加美观
  • Android 扫描二维码 条形码 Zbar
  • 使用VS2017中的Xamarin.Android进行开发,主要实现功能为:扫描二维码,并将扫描结果显示出来,如果结果为网址,则自动跳转到相应的网站。【注意,该项目使用VS2017,低版本的VS无法直接打开解决方案】
  • Android 扫描二维码条形码
  • *//导入ZXing依赖包* //导入依赖 compile 'pub.devrel:easypermissions:0.2.0' //必须要实现这个EasyPermissions.PermissionCallbacks public class MainActivity extends AppCompatActivity implements ...

    导入ZXing依赖包,已上传到GitHub

    点我去下载

    //导入依赖
    compile 'pub.devrel:easypermissions:0.2.0'
    
    //必须要实现这个
    public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks {
    
    private Button button1;
    private Button button;
    //用来判断是否成功
    private int REQUEST_CODE=111;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button1 = (Button) findViewById(R.id.button1);
        button = (Button) findViewById(R.id.button);
    
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
           		 //ThreeActivity是扫描二维码
                Intent intent = new Intent(getApplication(), ThreeActivity.class);
                //把这个常量传过去
                startActivityForResult(intent, REQUEST_CODE);
            }
        });
    
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
           		  //ThreeActivity是扫描二维码
                startActivity(new Intent(MainActivity.this, TwoActivity.class));
            }
        });
    }
    
    //回调
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if (requestCode==REQUEST_CODE){
            if (null!=data){
                Bundle bundle = data.getExtras();
                if (bundle==null){
                    return;
                }
                if (bundle.getInt(CodeUtils.RESULT_TYPE)==CodeUtils.RESULT_SUCCESS){
                    String result = bundle.getString(CodeUtils.RESULT_STRING);
                    Toast.makeText(MainActivity.this,"解析结果"+result,Toast.LENGTH_SHORT).show();
                }else if (bundle.getInt(CodeUtils.RESULT_TYPE)==CodeUtils.RESULT_FAILED){
                    Toast.makeText(MainActivity.this,"二维码解析失败",Toast.LENGTH_SHORT).show();
                }
            }
        }
    }
    
    @Override
    protected void onStart() {
        super.onStart();
        requestCodeQRCodePermissions();
    }
    
    检测权限
    private void requestCodeQRCodePermissions(){
        String[] perms={Manifest.permission.CAMERA,Manifest.permission.READ_EXTERNAL_STORAGE};
        if (!EasyPermissions.hasPermissions(this,perms)){
            EasyPermissions.requestPermissions(this,"扫描二维码需要打开相机和闪光灯的权限",REQUEST_CODE,perms);
        }
    }
    
    //动态获取权限
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        EasyPermissions.onRequestPermissionsResult(requestCode,permissions,grantResults,this);
    }
    
    @Override
    public void onPermissionsGranted(int requestCode, List<String> perms) {
    
    }
    
    @Override
    public void onPermissionsDenied(int requestCode, List<String> perms) {
    
    }
    }
    
    //扫描二维码
    public class ThreeActivity extends AppCompatActivity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ZXingLibrary.initDisplayOpinion(this);
        setContentView(R.layout.activity_three);
        CaptureFragment captureFragment=new CaptureFragment();
        captureFragment.setAnalyzeCallback(analyzeCallback);
        getSupportFragmentManager().beginTransaction().replace(R.id.fl_zxing_container,captureFragment).commit();
        captureFragment.setCameraInitCallBack(new CaptureFragment.CameraInitCallBack() {
            @Override
            public void callBack(Exception e) {
                if (e==null){
    
                }else {
                    Log.e("TAG","callBack",e);
                }
            }
        });
    }
    
     CodeUtils.AnalyzeCallback analyzeCallback=new CodeUtils.AnalyzeCallback() {
         @Override
         public void onAnalyzeSuccess(Bitmap mBitmap, String result) {
             Intent resultIntent = new Intent();
             Bundle bundle = new Bundle();
             bundle.putInt(CodeUtils.RESULT_TYPE,CodeUtils.RESULT_SUCCESS);
             bundle.putString(CodeUtils.RESULT_STRING,result);
             resultIntent.putExtras(bundle);
             ThreeActivity.this.setResult(RESULT_OK,resultIntent);
             ThreeActivity.this.finish();
         }
    
         @Override
         public void onAnalyzeFailed() {
             Intent resultIntent = new Intent();
             Bundle bundle = new Bundle();
             bundle.putInt(CodeUtils.RESULT_TYPE,CodeUtils.RESULT_FAILED);
             bundle.putString(CodeUtils.RESULT_STRING,"");
             resultIntent.putExtras(bundle);
             ThreeActivity.this.setResult(RESULT_OK,resultIntent);
             ThreeActivity.this.finish();
         }
     };
    }
    
    //生成二维码
    public class TwoActivity extends AppCompatActivity {
    
    private EditText editText;
    private Button button;
    private Button button1;
    private ImageView imageView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);
        editText = (EditText) findViewById(R.id.edit_content);
        button = (Button) findViewById(R.id.button_content);
        button1 = (Button) findViewById(R.id.button1_content);
        imageView = (ImageView) findViewById(R.id.image_content);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String textContent = editText.getText().toString();
                if (TextUtils.isEmpty(textContent)){
                    Toast.makeText(TwoActivity.this,"不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }
                editText.setText("");
               /* Resources res = getResources();
                Bitmap logo = BitmapFactory.decodeResource(res, R.mipmap.dd);*/
                Bitmap bitmap = CodeUtils.createImage(textContent, 400, 400, BitmapFactory.decodeResource(getResources(),R.mipmap.dd));
                imageView.setImageBitmap(bitmap);
            }
        });
    
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String textContent = editText.getText().toString();
                if (TextUtils.isEmpty(textContent)){
                    Toast.makeText(TwoActivity.this,"不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }
                editText.setText("");
                Bitmap bitmap = CodeUtils.createImage(textContent, 400, 400, null);
                imageView.setImageBitmap(bitmap);
            }
        });
    }
    }
    
    //扫描二维码的xml布局
     <FrameLayout
        android:id="@+id/fl_zxing_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    
    展开全文
  • 极客学院扫描二维码和生成二维码 package com.example.testqr; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import ...
  • 从zxing框架里提取出的Android端扫二维码的库和示例程序
  • android 基于zxing 完善的扫描demo 可以扫描二维码、条形码、pdf417格式条形码
  • 主要介绍了Android扫描二维码时出现用户禁止权限报错问题解决办法的相关资料,需要的朋友可以参考下
  • 用ZXING开发了二维码扫描,单扫描的时候出现了如图情况,扫描界面不成比例,请大神指点,这个问题怎么处理
  • Android 扫描二维码实现网页登录

    千次阅读 2014-12-24 20:26:46
    本套课程讲解了如何用Android 扫描二维码实现网页登录 视频地址 http://www.jikexueyuan.com/course/420.html

空空如也

1 2 3 4 5 ... 20
收藏数 3,252
精华内容 1,300
关键字:

android扫描二维码