After a week or so, I finally realized the QR code generation and scanning functions, and finally relieved me. From the very beginning, I wondered why different scanning clients have different effects? A common scanner downloads an APK. A self-made scanner scans out valid information and analyzes the information. In fact, a QR code simply records a simple information, generally a URL, then I will post on the URL myself! After learning the requirements, I started to generate the QR code, used the open-source framework QRCode, and then parsed ZXing. All of them stood on the shoulders of our predecessors and continued to do so, I didn't go into in-depth research on the deep-seated aspects of the QR code. I probably only know that the generated image is based on a two-dimensional Bool array and then draws a square image of the pixel parameter, the three corners and the middle are three small rectangles that do not contain information, to locate the location, there is a square area in the center that has no information for Logo placement. It is clearer than everyone. We have seen it all. Now, restaurants and subways usually have a scanned Logo, the QR code has become a common promotion tool! After receiving this task, I need to analyze the problem step by step to solve the problem, from generating a QR code image, to batch generation and then to the batch generation page, in addition, the corresponding QR code should be nested in each page, and then we will learn about Android, because we have never touched anything in the Java direction before, and then simply watched Android for two days, I have a general understanding of Android development, followed by the interaction between Android and Unity, and the Android plug-in. By tonight, I have finally implemented the function, there is nothing that can't be solved. As long as you do it, you just need to brainstorm, everything is OK!
Next, I will share with you the production process. I wrote a tutorial about generating QR codes, and the results were also attacked. net programmers are at your level... I am really ashamed of this netizen. My level is limited, and the content I write is really simple, and it cannot satisfy your technical eyes, however, I wrote it to attract more beginners and hope to help them get started! I want to talk about other people. Don't look down on a newbie or a person without your skills if you think you are amazing. Maybe in the future, he may be more technical than you! All in all, for Daniel, the generation and resolution of the QR code is very simple, but I still stick to it. It is also a summary of myself over the past week, second, I hope to learn and make progress together with the majority of beginners!
For information on generating and interacting with QR codes, see my previous article: generate a QR code token. On this basis, and then implement the function!
More exciting content please pay attention to my microblogging http://weibo.com/dingxiaowei2013 reprint please indicate the source: http://blog.csdn.net/dingxiaowei2013/article/details/24677795
:
Mobile phone scan results:
Note: The Java method of Android is called on the Unity interface to jump to the Activity view of Android development. Then, the Java method of Android calls Unity and returns to the Unity interface.
Source code Unity:
Using UnityEngine; using System. collections; public class NewBehaviourScript: MonoBehaviour {private AndroidJavaObject activity; private string result = "http://blog.csdn.net/dingxiaowei2013"; // result is used to receive the return value of the QR code void Start () {AndroidJavaClass jc = new AndroidJavaClass ("com. unity3d. player. unityPlayer "); activity = jc. getStatic <AndroidJavaObject> ("currentActivity");} void OnGUI () {// click the scan code to call the Android method if (GUI. button (new Rect (Screen. width/2-50, 20,100, 50), "click to scan") {activity. call ("Show");} GUI. label (new Rect (Screen. width/2-100,120,300, 20), result);} // This is the void GetString (string str) {result = str ;}} method called by Android ;}}
Android:
Package com. example. qr_codescan; import android. content. intent; import android. OS. bundle; import android. widget. imageView; import android. widget. textView; import com. unity3d. player. unityPlayer; import com. unity3d. player. unityPlayerActivity; public class MainActivity extends UnityPlayerActivity {private final static int SCANNIN_GREQUEST_CODE = 1;/*** display scan result */private TextView mTextView; /*** display scanned image */private ImageView mImageView; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // setContentView (R. layout. activity_main); // mTextView = (TextView) findViewById (R. id. result); // mImageView = (ImageView) findViewById (R. id. qrcode_bitmap); ///// click the Button to jump to the QR code scanning page. startActivityForResult is used to jump to the page. /// after scanning, adjust it to the page. // Button mButton = (Button) findViewById (R. id. button1); // mButton. setOnClickListener (new OnClickListener () {// @ Override // public void onClick (View v) {// Intent intent = new Intent (); // intent. setClass (MainActivity. this, MipcaActivityCapture. class); // intent. setFlags (Intent. FLAG_ACTIVITY_CLEAR_TOP); // startActivityForResult (intent, SCANNIN_GREQUEST_CODE); //});} public void Show () {Intent intent = new Intent (); intent. setClass (MainActivity. this, MipcaActivityCapture. class); intent. setFlags (Intent. FLAG_ACTIVITY_CLEAR_TOP); startActivityForResult (intent, SCANNIN_GREQUEST_CODE);} @ Override protected void onActivityResult (int requestCode, int resultCode, Intent data) {super. onActivityResult (requestCode, resultCode, data); switch (requestCode) {case SCANNIN_GREQUEST_CODE: if (resultCode = RESULT_ OK) {Bundle bundle = data. getExtras (); // display the scanned content // mTextView. setText (bundle. getString ("result"); // display // mImageView. setImageBitmap (Bitmap) data. getParcelableExtra ("bitmap"); UnityPlayer. unitySendMessage ("Cube", "GetString", bundle. getString ("result") ;}break ;}}}
Export plug-in: Then I export it as a plug-in. The previous code scanning plug-in was easycode.pdf, and my future network name was Aladdin. I also named it an Android plug-in named aladdincode.pdf, in the future, I may continue to complete the code scanning function for IOS, and improve this plug-in. I am also suffering from easycodebench, so I decided to do it myself! We found a plug-in easycode.pdf which used to scan the QR code. The result showed that there was an error. The key was that the Android code scanning function was not implemented, and some Android methods were not implemented, so it also contributed to my own idea of writing plug-ins. Today, I wish I could do it with ease! It's not too early. I feel a little overwhelmed when I stay up late. My health is the cost, and tomorrow I will continue to complete the project! Good night!