您的位置:首页 > 其它

扫描二维码和生成二维码

2015-07-13 13:41 288 查看
public class MainActivity extends Activity implements OnClickListener{

private TextView textView;
private EditText editText1;
private Button button1;
private Button saomao;
private ImageView imageView1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
saomao = (Button) findViewById(R.id.saomao);
textView = (TextView) findViewById(R.id.textView1);
button1 = (Button) findViewById(R.id.button1);
editText1 = (EditText) findViewById(R.id.editText1);
imageView1 = (ImageView) findViewById(R.id.imageView1);

saomao.setOnClickListener(this);
button1.setOnClickListener(this);
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.saomao:
Intent intent = new Intent(this, CaptureActivity.class);
startActivityForResult(intent, 0);
break;
case R.id.button1:
String string = editText1.getText().toString().trim();
if (string.equals("")) {
Toast.makeText(MainActivity.this, "请输入文本", 0).show();
}else {
try {
Bitmap bitmap = EncodingHandler.createQRCode(string, 400);
imageView1.setImageBitmap(bitmap);

} catch (WriterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
default:
break;
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
String result = data.getExtras().getString("result");
textView.setText(result);
}
}

}
源码下载
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: