MainActivity
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
private final int REQUESTCODE = 0;//请求吗
private final int RESULTCODE = 1;//结果码
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button start = (Button) findViewById(R.id.start);
Button create = (Button) findViewById(R.id.create);
final EditText content = (EditText) findViewById(R.id.content);
final ImageView bit = (ImageView) findViewById(R.id.bit);
textView = (TextView) findViewById(R.id.result_0);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textView.setText("");
Intent intent = new Intent(MainActivity.this,CaptureActivity.class);
startActivityForResult(intent,REQUESTCODE);
}
});
create.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String content_string = content.getText().toString();
Log.d(TAG, "onClick() returned: " + "取到的内容---" + content_string);
Bitmap bitmap = EncodingUtils.createQRCode(content_string, 200, 200, null);
bit.setImageBitmap(bitmap);
}
});
}
//接收返回结果
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult() returned: " + "接收结果.....");
if (resultCode==RESULT_OK){
Log.d(TAG, "onActivityResult() returned: " + "返回成功");
Bundle bundle = data.getExtras();
String result = bundle.getString("result");
textView.setText(result);
Log.d(TAG,"----"+result+"---");
}
}
}
activity_main
<!--
扫描页面
-->
<Button
android:id="@+id/start"
android:text="开始扫描"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/img0"
android:src="@drawable/aaaa"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/img1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
one_activity
<!--
扫描页面
-->
<Button
android:id="@+id/start"
android:text="开始扫描"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/img0"
android:src="@drawable/aaaa"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/img1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>