zoukankan      html  css  js  c++  java
  • 二维码扫描

    public class MainActivity extends AppCompatActivity {
    
        private TextView tv;
       int REQUEST_CODE=1;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tv = (TextView) findViewById(R.id.tv);
            tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(MainActivity.this, CaptureActivity.class);
                    startActivityForResult(intent, REQUEST_CODE);
    
                }
            });
        }
        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            CodeUtils.isLightEnable(true);
            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_LONG).show();
                    } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) {
                        Toast.makeText(MainActivity.this, "解析二维码失败", Toast.LENGTH_LONG).show();
                    }
                }
            }
        }
    
    }
    

      myApp:

    public class MyApp extends Application{
    @Override
    public void onCreate() {
    super.onCreate();
    ZXingLibrary.initDisplayOpinion(this);

    }
    }

    主xml;

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.bwei.test.myapplication.MainActivity">

    <TextView android:layout_width="wrap_content"
    android:id="@+id/tv"
    android:layout_height="wrap_content"
    android:text="Hello World!" />
    </RelativeLayout>

    values  dimens

    <resources>
    <!-- Example customization of dimensions originally defined in res/values/dimens.xml
    (such as screen margins) for screens with more than 820dp of available width. This
    would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
    <dimen name="activity_horizontal_margin">64dp</dimen>
    </resources>

  • 相关阅读:
    centos7不能上网问题
    数据库修改为utf8mb4
    查看Linux系统信息
    如何查看Linux是否安装了gcc和gcc-c++
    nginx启动报错
    centos7无法上网问题
    notepad++如何将换行替换成其它符号?
    JAVA DESUtils加密工具
    Django之Model(一)--基础篇
    深刻理解Python中的元类(metaclass)以及元类实现单例模式
  • 原文地址:https://www.cnblogs.com/wsq110/p/7791503.html
Copyright © 2011-2022 走看看