当前位置:   article > 正文

Android 二维码编程_修改app面面二维码代码

修改app面面二维码代码

这两天一直忙这帮老师整理国家资源库的视频了 ,又是录制又是剪辑,又是写字幕,快忙死了,本来不会那些视频制作一类的软件,现在我都可以拍电影了。

没有时间做自己的项目了,昨天晚上加班把二维码搞出来了。本来以为特别麻烦,没想到。。。。简直不用智商啊。

那两天搞二维码没有头绪,就网上找资料,查资料, 对亏看到传智播客上的视频了,就照骆驼画马了。竟然可以。

又废话了......



让你开发二维码   听起来就瘆的慌。但我们又官方提供的开源代码,可以参考。Zxing

https://github.com/zxing/zxing  里面有代码   但工程太大。但我们有高手整理出来的精简版的,我们直接用就可以。

我本来想自己整理一份,我就一份份改,我去,类与类之间关系太紧了,花了两个小时的干出一大堆,最后还是有错,算了还是用前辈的吧,不要重复发明轮子嘛,没意义。




一 .导入文件

首先导入一些Android文件工程(我会提供源代码的)

导入时需要注意一个问题 直接上图



二 . 使它成为外部项目可以引用的库

导进去后我们找到项目   属性 -->Android-->左下角有一个Library 我们需要打上勾。


这样的话外部的项目就可以引用它了。   因为单独一个二维码扫描 解码 完全没有意义。

三. 新建自己的项目



新建完后我们 需要进行引用导入的这个项目。
同样进入项目属性  Android  右下角有添加外部项目



四 .做完这些后就添加权限  和  注册页面


打开我们导入项目的 AndroidManifest.xml 把他所需要的条件 添加到  新建的项目中的AndroidManifest.xml


添加那些呢???




好了。我们先写自己的界面



  1. <span style="font-size:14px;"><span style="color:#000099;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:paddingBottom="@dimen/activity_vertical_margin"
  6. android:paddingLeft="@dimen/activity_horizontal_margin"
  7. android:paddingRight="@dimen/activity_horizontal_margin"
  8. android:paddingTop="@dimen/activity_vertical_margin"
  9. tools:context=".MainActivity"
  10. </span><span style="color:#ffcc33;">android:background="@drawable/a002"</span><span style="color:#000099;"> >
  11. <Button
  12. android:id="@+id/buttonscan"
  13. android:layout_width="fill_parent"
  14. android:layout_height="wrap_content"
  15. android:layout_alignParentTop="true"
  16. android:layout_centerHorizontal="true"
  17. android:textColor="#FF0000"
  18. android:text="Scan" />
  19. <TextView
  20. android:id="@+id/textViewshow"
  21. android:layout_width="fill_parent"
  22. android:layout_height="40dp"
  23. android:layout_below="@+id/buttonscan"
  24. android:gravity="center_horizontal|center_vertical"
  25. android:text="Show" />
  26. <ImageView
  27. android:id="@+id/imageview"
  28. android:layout_width="wrap_content"
  29. android:layout_height="wrap_content"
  30. android:layout_below="@+id/buttonprint"
  31. android:layout_centerHorizontal="true"
  32. android:layout_marginTop="46dp" />
  33. <Button
  34. android:id="@+id/buttonprint"
  35. android:layout_width="fill_parent"
  36. android:layout_height="wrap_content"
  37. android:layout_alignParentRight="true"
  38. android:layout_below="@+id/editText1"
  39. android:textColor="#FF00FF"
  40. android:text="Ok,Print" />
  41. <Button
  42. android:id="@+id/buttonclear"
  43. android:layout_width="fill_parent"
  44. android:layout_height="wrap_content"
  45. android:layout_alignLeft="@+id/textViewshow"
  46. android:layout_below="@+id/textViewshow"
  47. android:textColor="#00FFFF"
  48. android:text="清除Show" />
  49. <EditText
  50. android:id="@+id/editText1"
  51. android:layout_width="fill_parent"
  52. android:layout_height="wrap_content"
  53. android:layout_alignLeft="@+id/buttonclear"
  54. android:layout_below="@+id/buttonclear"
  55. android:ems="10"
  56. android:gravity="center_horizontal"
  57. android:hint="请输入您要生成的信息" />
  58. </RelativeLayout></span></span>

然后写主程序

  1. <span style="font-size:14px;"><span style="color:#990000;">package com.example.qrdemo;
  2. import com.google.zxing.WriterException;
  3. import com.zxing.activity.CaptureActivity;
  4. import com.zxing.encoding.EncodingHandler;
  5. import android.os.Bundle;
  6. import android.app.Activity;
  7. import android.content.Intent;
  8. import android.graphics.Bitmap;
  9. import android.view.Menu;
  10. import android.view.View;
  11. import android.view.Window;
  12. import android.widget.Button;
  13. import android.widget.EditText;
  14. import android.widget.ImageView;
  15. import android.widget.TextView;
  16. import android.widget.Toast;
  17. public class MainActivity extends Activity
  18. {
  19. private Button Scan;
  20. private TextView textView;
  21. private EditText Input;
  22. private Button Print;
  23. private ImageView Image;
  24. private Button Clear;
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState)
  27. {
  28. super.onCreate(savedInstanceState);
  29. this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  30. setContentView(R.layout.activity_main);
  31. Scan = (Button)findViewById(R.id.buttonscan);
  32. textView = (TextView)findViewById(R.id.textViewshow);
  33. Input = (EditText)findViewById(R.id.editText1);
  34. Print = (Button)findViewById(R.id.buttonprint);
  35. Image =(ImageView)findViewById(R.id.imageview);
  36. Clear =(Button)findViewById(R.id.buttonclear);
  37. Scan.setOnClickListener(new View.OnClickListener()
  38. {
  39. @Override
  40. public void onClick(View arg0)
  41. {
  42. // TODO Auto-generated method stub
  43. Intent newactvity =new Intent(MainActivity.this,CaptureActivity.class);
  44. //startActivity(newactvity);
  45. startActivityForResult(newactvity,0);
  46. //startActivityForResult (Intent intent, int requestCode)
  47. //相同调用活动返回结果不带任何选项
  48. }
  49. });
  50. Clear.setOnClickListener(new View.OnClickListener()
  51. {
  52. @Override
  53. public void onClick(View arg0)
  54. {
  55. // TODO Auto-generated method stub
  56. textView.setText("");
  57. }
  58. });
  59. Print.setOnClickListener(new View.OnClickListener()
  60. {
  61. @Override
  62. public void onClick(View arg0)
  63. {
  64. // TODO Auto-generated method stub
  65. String inputmessage = Input.getText().toString();
  66. if(inputmessage.equals(null))
  67. {
  68. Toast.makeText(MainActivity.this, "请输入您要合成的数据",Toast.LENGTH_SHORT).show();
  69. }else
  70. {
  71. try
  72. {
  73. Bitmap qrbitmap = EncodingHandler.createQRCode(inputmessage,800);
  74. Image.setImageBitmap(qrbitmap);
  75. } catch (WriterException e)
  76. {
  77. // TODO Auto-generated catch block
  78. e.printStackTrace();
  79. }
  80. }
  81. }
  82. });
  83. }
  84. protected void onActivityResult(int requestCode,int resultCode,Intent data)//结果处理函数
  85. /*
  86. * 活动启动时调用退出,让您请求码你开始用,结果代码返回,并且从它的任何其他数据。
  87. * 如果活动,将RESULT_CANCELED的结果代码显式地返回,
  88. * 没有返回任何结果,或在其操作期间坠毁。
  89. * */
  90. {
  91. super.onActivityResult(requestCode,resultCode,data);
  92. if(resultCode == RESULT_OK)//标准活动结果:操作成功
  93. {
  94. String result = data.getExtras().getString("result");//getExtras()从意图检索扩展数据的map。
  95. textView.setText(result);
  96. }
  97. }
  98. }</span><span style="background-color: rgb(0, 153, 0);">
  99. </span></span>

给你们几张  API的截图          反正上边几个函数方法我不太不明白   然后就查了查API 清楚了些




不懂英文,像我一样用电子词典


好吧 完了 就这些而已  因为我们调用的开源的,所以不用太麻烦。

看一下结果吧啊。。



OK完了,


源代码    源代码下载                                                http://download.csdn.net/detail/csdnhejingzhou/9241763


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号