Zxing二维码-引用QRCode类库

package com.wpl.zxing.zxing_demo;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.xys.libzxing.zxing.activity.CaptureActivity;
import com.xys.libzxing.zxing.encoding.EncodingUtils;

public class MainActivity extends AppCompatActivity {

    private TextView mTv;
    private EditText mEd;
    private ImageView mImg;

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

        //获取控件
        mEd = (EditText) findViewById(R.id.ed);
        Button but1 = (Button) findViewById(R.id.but1);
        Button but2 = (Button) findViewById(R.id.but2);
        mImg = (ImageView) findViewById(R.id.img);
        mTv = (TextView) findViewById(R.id.tv);

        //点击事件
        but1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bitmap code = EncodingUtils.createQRCode(mEd.getText().toString().trim(), 200, 200, null);
                mImg.setImageBitmap(code);
            }
        });
        but2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, CaptureActivity.class);
                startActivityForResult(intent,200);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode==200){
            String result = data.getStringExtra("result");
            mTv.setText(result);
        }
    }
}

你可能感兴趣的:(Zxing二维码-引用QRCode类库)