二维码

来源:互联网 发布:淘宝直播怎么申请不了 编辑:程序博客网 时间:2024/04/26 22:00
public class MainActivity extends Activity {private Button mButton01;private EditText mEditText01;private WebView mWebView01;private boolean bInternetConnectivity = false;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);bInternetConnectivity = true;mWebView01 = (WebView) findViewById(R.id.myWebView1);mButton01 = (Button) findViewById(R.id.myButton1);mEditText01 = (EditText) findViewById(R.id.myEditText1);mEditText01.setHint("请输入内容");mButton01.setOnClickListener(new Button.OnClickListener() {@Overridepublic void onClick(View v) {String mess = mEditText01.getText().toString().trim();if (mess != "" && bInternetConnectivity == true) {/* 调用自定义云端生成QR Code函数 */mWebView01.loadData(genGoogleQRChart(mess, 200),"text/html", "utf-8");}}});}public String genGoogleQRChart(String strToQRCode, int strWidth) {String strReturn = "";try {strReturn = new String(strToQRCode.getBytes("utf-8"));/* 组成Google API需要的传输参数字符串 */strReturn = "<html><body>"+ "<img src=http://chart.apis.google.com/chart?chs="+ strWidth + "x" + strWidth + "&chl="+ URLEncoder.encode(strReturn, "utf-8")+ "&choe=UTF-8&cht=qr></body></html>";} catch (Exception e) {e.printStackTrace();}return strReturn;}/* 自定义BIG5转UTF-8 */public String big52unicode(String strBIG5) {String strReturn = "";try {strReturn = new String(strBIG5.getBytes("big5"), "UTF-8");} catch (Exception e) {e.printStackTrace();}return strReturn;}/* 自定义UTF-8转BIG5 */public String unicode2big5(String strUTF8) {String strReturn = "";try {strReturn = new String(strUTF8.getBytes("UTF-8"), "big5");} catch (Exception e) {e.printStackTrace();}return strReturn;}}

原创粉丝点击