我有问题我创建小型应用程序时首先获取短信代码,如果长度大于六,请转到活动 B。活动 B 显示扫描二维码。扫描二维码使用库谷歌播放服务视觉扫描二维码。如果值正确,则使用条形码获取价值并与短信代码混合,如果不去活动 A,则转到活动 C。我的问题是如何获取价值短信代码和条形码值以及在哪里进行 ctrytography。
这是带有获取短信代码的课程
public class SmsCodeActivity extends AppCompatActivity implements View.OnClickListener {
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
}
public final static String EXTRA_MESSAGE = "smsCode";
private EditText smsCode;
private Button checkSmsCodeButton;
private TextView text_info;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms_code);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationIcon(R.drawable.ic_restart);
Typeface custom_fonts = Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Light.ttf");
Typeface custom_fonts2 = Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Regular.ttf");
TextView titleActivity = (TextView) findViewById(R.id.smsTitle);
titleActivity.setTypeface(custom_fonts2);
TextView subtitleApplication = (TextView) findViewById(R.id.stage1TextView);
subtitleApplication.setTypeface(custom_fonts2);
TextView subtitleText = (TextView) findViewById(R.id.subtitle_text);
subtitleText.setTypeface(custom_fonts);
text_info = (TextView) findViewById(text_Info);
text_info.setTypeface(custom_fonts2);
text_info.setVisibility(View.INVISIBLE);
smsCode = (EditText) findViewById(R.id.editTextSmsCode);
smsCode.setTypeface(custom_fonts);
checkSmsCodeButton = (Button) findViewById(R.id.buttonSmsCode);
checkSmsCodeButton.setTypeface(custom_fonts2);
checkSmsCodeButton.setOnClickListener(this);
setSupportActionBar(toolbar);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.buttonSmsCode) {
String smsText = smsCode.getText().toString();
if (smsText.isEmpty()) {
text_info.setVisibility(View.VISIBLE);
text_info.setText("Nie podałeś SMS Kodu");
} else if (smsText.length() < 6) {
text_info.setVisibility(View.VISIBLE);
text_info.setText("Podany SMS Kod jest za krótki");
} else if (smsText.length() == 6) {
Intent intent = new Intent(SmsCodeActivity.this, ScanQrCodeActivity.class);
intent.putExtra(EXTRA_MESSAGE, smsText);
startActivity(intent);
}
}
}
}
这是带有扫描或代码的课程
public class ScanQrCodeActivity extends AppCompatActivity {
SurfaceView cameraPreview;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan_qr_code);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.ic_restart);
Typeface custom_fonts = Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Regular.ttf");
TextView title_app = (TextView) findViewById(R.id.title_application_scan);
title_app.setTypeface(custom_fonts);
cameraPreview = (SurfaceView) findViewById(R.id.cameraPreview);
createCameraSource();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
private void createCameraSource() {
BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(this).build();
final CameraSource cameraSource = new CameraSource.Builder(this, barcodeDetector)
.setAutoFocusEnabled(true)
.setRequestedPreviewSize(1600, 1024)
.build();
cameraPreview.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (PackageManager.PERMISSION_GRANTED == ActivityCompat.checkSelfPermission(ScanQrCodeActivity.this, Manifest.permission.CAMERA)) {
try {
cameraSource.start(cameraPreview.getHolder());
} catch (IOException e) {
e.printStackTrace();
}
} else {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
cameraSource.stop();
}
});
barcodeDetector.setProcessor(new Detector.Processor<Barcode>() {
@Override
public void release() {
}
@Override
public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> barcodes = detections.getDetectedItems();
if (barcodes.size() > 0) {
}
}
});
}
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
public Action getIndexApiAction() {
Thing object = new Thing.Builder()
.setName("ScanQrCode Page") // TODO: Define a title for the content shown.
// TODO: Make sure this auto-generated URL is correct.
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}
@Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
AppIndex.AppIndexApi.start(client, getIndexApiAction());
}
@Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
AppIndex.AppIndexApi.end(client, getIndexApiAction());
client.disconnect();
}
}