验证中...
语言: Java
分类: Android 组件
最后更新于 2018-02-13 14:19
二维码
原始数据 复制代码
public class MainActivity extends Activity {
private TextView tv_result;
String info="";
String result="";
Handler handler;
Button submit;
String sname= EMProApplicationDelegate.userInfo.getUserId();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//tv_result = (TextView)findViewById(R.id.textView);
//标题栏
ImageButton backBtn = findViewById(R.id.title_back_btn);
ImageButton mainBtn=(ImageButton) findViewById(R.id.main_menu_bn);
mainBtn.setVisibility(View.INVISIBLE);
TextView textView = findViewById(R.id.title_tv);
textView.setText("烧录扫描"+sname);
backBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
if(result.equals("true")){
Toast.makeText(MainActivity.this,"扫描成功!", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(MainActivity.this,"扫描失败!", Toast.LENGTH_SHORT).show();
}
}
};
ImageButton butnSweep=findViewById(R.id.imageButton);
//butnSweep.setImageResource(R.mipmap.ic_action_camera_scan);
butnSweep.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sweep(v);
}
});
}
public void sweep(View view) {
Intent intent = new Intent();
intent.setClass(this, CaptureActivity.class);
intent.putExtra("autoEnlarged",true);
startActivityForResult(intent,0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
/* if (resultCode == Constants.EM_QRCODE_RESULT_CODE &&
requestCode == Constants.EM_QRCODE_REQUEST_CODE) {
info=data.getStringExtra(Constants.EM_QRCODE_RESULT_TAG).trim();*/
if(requestCode==0 && resultCode==RESULT_OK && data!=null){
info = data.getStringExtra("result");
info=recode(info);
//tv_result.setText(info);
if (info == null || "".equals(info)) {
Toast.makeText(MainActivity.this, "扫描失败!", Toast.LENGTH_SHORT).show();
} else {
com.zhengyuan.emburnsweep.DataObtainer.INSTANCE.sendBurnSweepMessage(info,
new NetworkCallbacks.SimpleDataCallback() {
@Override
public void onFinish(boolean b, String s, Object o) {
if (o.equals("")) {
Utils.showToast("未查询到信息");
return;
}
result = (String) o;
Message m = handler.obtainMessage();
handler.sendMessage(m);
//Log.d("WDRActivity1", "result1: " + result1);
}
}
);
}
}
}
//解决乱码问题
private String recode(String str) {
String formart = "";
try {
boolean ISO = Charset.forName("ISO-8859-1").newEncoder()
.canEncode(str);
if (ISO) {
formart = new String(str.getBytes("ISO-8859-1"), "GB2312");
Log.i("1234 ISO8859-1", formart);
} else {
formart = str;
Log.i("1234 stringExtra", str);
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return formart;
}
}

评论列表( 0 )

你可以在登录后,发表评论

搜索帮助