QR_CODE GENERATOR IN ANDROID
History
The QR code system was invented in 1994 by Denso Wave. Its purpose was to track vehicles during manufacture; it was designed to allow high-speed component scanning.[3]Although initially used for tracking parts in vehicle manufacturing, QR codes now are used in a much broader context, including both commercial tracking applications and convenience-oriented applications aimed at mobile-phone users (termed mobile tagging). QR codes may be used to display text to the user, to add a vCard contact to the user's device, to open a Uniform Resource Identifier (URI), or to compose an e-mail or text message. Users can generate and print their own QR codes for others to scan and use by visiting one of several paid and free QR code generating sites or apps. The technology has since become one of the most-used types of two-dimensional barcode.[4]
1.What is QR_code ?A machine-readable code consisting of an array of black and white squares, typically used for storing URLs or other information for reading by the camera on a smartphone.
2.How could you use a QR code?
Your business, no matter how small or large, could use QR codes in a number of ways. You might auto generate one next to every product on your web site containing all the product details, the number to call and the URL link to the page so they can show their friends on their cell phone. You could add one to your business card containing your contact details so its easy for someone to add you to their contacts on their cell phone.
Add them to any print advertising, flyers, posters, invites, TV ads etc containing:
- Product details
- Contact details
- Offer details
- Event details
- Competition details
- A coupon
- Twitter, Facebook, MySpace IDs
- A link to your YouTube video
3.Storage?
The amount of data that can be stored in the QR code symbol depends on the datatype (mode, or input character set), version (1, …, 40, indicating the overall dimensions of the symbol), and error correction level. The maximum storage capacities occur for 40-L symbols (version 40, error correction level L)
Input mode | max. characters | bits/char | possible characters, default encoding |
---|---|---|---|
Numeric only | 7,089 | 3⅓ | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 |
Alphanumeric | 4,296 | 5½ | 0–9, A–Z (upper-case only), space, $, %, *, +, -, ., /, : |
Binary/byte | 2,953 | 8 | ISO 8859-1 |
4.Encoding?
The format information records two things: the error correction level and the mask pattern used for the symbol. Masking is used to break up patterns in the data area that might confuse a scanner, such as large blank areas or misleading features that look like the locator marks. The mask patterns are defined on a grid that is repeated as necessary to cover the whole symbol. Modules corresponding to the dark areas of the mask are inverted. The format information is protected from errors with a BCH code, and two complete copies are included in each QR symbol.
5.Structure?
QR CODE GENERATOR EXAMPLE CODE FOR ANDROID
1.Activitymain.xml
2.MainActivity.java
3.Add the library zing,.jar core.jar insert into the libs folder
project workspace screen short:
1. Activitymain.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#98222383"
tools:context="${relativePackage}.${activityClass}" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:ems="10" >
<requestFocus />
</EditText>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:text="Submit" />
</RelativeLayout>
2.MainActivity.java
package com.RSA.qrcode;
import java.util.EnumMap;
import java.util.Map;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
public class MainActivity extends Activity {
EditText value;
Button btn_submit;
ImageView code;
private static final int WHITE = 0xFFFFFFFF;
private static final int BLACK = 0xFF000000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
value=(EditText) findViewById(R.id.editText1);
btn_submit=(Button) findViewById(R.id.button1);
code=(ImageView) findViewById(R.id.imageView1);
btn_submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String a=value.getText().toString();
String qr_code = a;
Bitmap bitmap = null;
try {
bitmap = encodeAsBitmap(qr_code,BarcodeFormat.QR_CODE, 600, 300);
code.setImageBitmap(bitmap);
} catch (WriterException e) {
e.printStackTrace();
}
}
});
}
Bitmap encodeAsBitmap(String contents, BarcodeFormat format, int img_width,
int img_height) throws WriterException {
String contentsToEncode = contents;
if (contentsToEncode == null) {
return null;
}
Map<EncodeHintType, Object> hints = null;
String encoding = guessAppropriateEncoding(contentsToEncode);
if (encoding != null) {
hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, encoding);
}
MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix result;
try {
result = writer.encode(contentsToEncode, format, img_width,
img_height, hints);
} catch (IllegalArgumentException iae) {
// Unsupported format
return null;
}
int width = result.getWidth();
int height = result.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
int offset = y * width;
for (int x = 0; x < width; x++) {
pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
private static String guessAppropriateEncoding(CharSequence contents) {
// Very crude at the moment
for (int i = 0; i < contents.length(); i++) {
if (contents.charAt(i) > 0xFF) {
return "UTF-8";
}
}
return null;
}
}
output screen short:
Comments
Post a Comment