Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

android - How to store the Generated QR-Code as an image in SDCard (ZXing library)

I m making an app based on QR code. I have to Generate a QR-Code of a specific String and also I have to save the generated QR-Code in SD card. is it possible using the Zxing Library.

So for I am able to generate the QR-Code, using the following code.

Note:I m calling the QR-Code Scanner via Intent. I m inserting the input using an EditText Field right now. see code below

public class MainActivity extends Activity {

EditText edQR_Field;
Button btnGenerate_QR_Code;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btnGenerate_QR_Code = (Button) findViewById(R.id.button1);
    edQR_Field = (EditText) findViewById(R.id.editText1);

    btnGenerate_QR_Code.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            String input = edQR_Field.getText().toString();

            Intent intent = new Intent(
                    "com.google.zxing.client.android.ENCODE");

            intent.putExtra("ENCODE_TYPE", "TEXT_TYPE");
            intent.putExtra("ENCODE_DATA", input);
            intent.putExtra("ENCODE_FORMAT", "QR_CODE");
            intent.putExtra("ENCODE_SHOW_CONTENTS", false);
            startActivityForResult(intent, 0);

            Toast.makeText(MainActivity.this, input, Toast.LENGTH_SHORT)
                    .show();

        }
    });

}

 }

and I m getting this.

enter image description here

Question

I just want to save this Generated QR-Code in the SD card of my android device.

Regards Qadir Hussain

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can't cause the image to be saved, or get the image back, if you're integrating by Intent. However the user can save the image by pressing Menu and Share.

Instead you will simply need to embed the core library from the project and call it to encode the image. Then you can display or save or do what you like.

You can see how it's done in the app here, and reuse parts of this code: https://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/encode/EncodeActivity.java


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...