二维码(ZXing)

MainActivity

public class MainActivity extends AppCompatActivity {

private static final String TAG = "MainActivity";
private final int REQUESTCODE = 0;//请求吗
private final int RESULTCODE = 1;//结果码
private TextView textView;

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

    Button start = (Button) findViewById(R.id.start);
    Button create = (Button) findViewById(R.id.create);
    final EditText content = (EditText) findViewById(R.id.content);
    final ImageView bit = (ImageView) findViewById(R.id.bit);
    textView = (TextView) findViewById(R.id.result_0);
    start.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            textView.setText("");
            Intent intent  = new Intent(MainActivity.this,CaptureActivity.class);
            startActivityForResult(intent,REQUESTCODE);
        }
    });
    create.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String content_string = content.getText().toString();
            Log.d(TAG, "onClick() returned: " + "取到的内容---" + content_string);
            Bitmap bitmap = EncodingUtils.createQRCode(content_string, 200, 200, null);
            bit.setImageBitmap(bitmap);
        }
    });
}

//接收返回结果


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

    Log.d(TAG, "onActivityResult() returned: " + "接收结果.....");

    if (resultCode==RESULT_OK){
        Log.d(TAG, "onActivityResult() returned: " + "返回成功");
        Bundle bundle = data.getExtras();
        String result = bundle.getString("result");
        textView.setText(result);
        Log.d(TAG,"----"+result+"---");
    }

}

}

activity_main

<!--
    扫描页面
-->

<Button
    android:id="@+id/start"
    android:text="开始扫描"
    android:textSize="30sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
<ImageView
    android:id="@+id/img0"
    android:src="@drawable/aaaa"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
<ImageView
    android:id="@+id/img1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

one_activity

<!--
    扫描页面
-->

<Button
    android:id="@+id/start"
    android:text="开始扫描"
    android:textSize="30sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
<ImageView
    android:id="@+id/img0"
    android:src="@drawable/aaaa"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
<ImageView
    android:id="@+id/img1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值