package cgg.com.zxingbar; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; import com.dash.zxinglibrary.activity.CaptureActivity; import com.dash.zxinglibrary.activity.CodeUtils; public class MainActivity extends AppCompatActivity { private final int REQUESTCODE = 0x00001; private EditText editText; private ImageView imageView; private TextView result1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); editText = findViewById(R.id.content); imageView= findViewById(R.id.img); result1 = findViewById(R.id.result); } public void scanEWM(View view) { Intent intent = new Intent(MainActivity.this,CaptureActivity.class); startActivityForResult(intent,REQUESTCODE); } public void createEWM(View view) { String content_string = editText.getText().toString(); Log.d("TAG", "onClick() returned: " + "取到的内容---" + content_string); Bitmap logo = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); Bitmap bitmap = CodeUtils.createImage(content_string, 500, 500,logo); imageView.setImageBitmap(bitmap); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.d("AAA", "onActivityResult() returned: " + "接收结果....."); if (resultCode==RESULT_OK){ // Log.d(TAG, "onActivityResult() returned: " + "返回成功"); Bundle bundle = data.getExtras(); String result = bundle.getString("result"); result1.setText(result); } } }
public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); //初始化zxing ZXingLibrary.initDisplayOpinion(this); } }
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.FLASHLIGHT" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" />