0
(zxing을 사용하여) QR 코드를 스캔하여 개인 저장소에 저장하려고 결정한 경우 제대로 작동하는 다음 코드를 작성했지만 스캔을 취소하기로 결정한 경우 이전에 저장 한 파일과 충돌합니다 콘텐츠가 사라집니다.android zxing intentintegrator
디자인 오류 일 수 있습니다. 이유는 확실하지 않습니다.
는 아래 resultCode
을 확인
...
/**
* menu generation
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
/**
* menu handling
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Context context = getApplicationContext();
Toast toast = Toast.makeText(context, "", Toast.LENGTH_LONG);
toast.setGravity(Gravity.FILL_HORIZONTAL, 0, 0);
switch (item.getItemId()) {
case R.id.qrScan:
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
return true;
case R.id.qrReset:
File dir = getFilesDir();
File file = new File(dir, qrCodeFile);
boolean deleted = file.delete();
return true;
case R.id.appClose:
this.finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
...
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
Context context = getApplicationContext();
Toast toast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
if (scanResult != null) {
FileOutputStream fos = null;
CharSequence text = scanResult.getContents();
try {
fos = openFileOutput(qrCodeFile, Context.MODE_PRIVATE);
try {
fos.write(text.toString().getBytes());
fos.close();
toast.setGravity(Gravity.FILL_HORIZONTAL, 0, 0);
toast.setText("Code saved");
toast.show();
} catch (IOException ex) {
toast.setGravity(Gravity.FILL_HORIZONTAL, 0, 0);
toast.setText("Invalid code");
toast.show();
Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (FileNotFoundException ex) {
toast.setGravity(Gravity.FILL_HORIZONTAL, 0, 0);
toast.setText("Error while saving");
toast.show();
Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
toast.setGravity(Gravity.FILL_HORIZONTAL, 0, 0);
toast.setText("Invalid code");
toast.show();
}
}
고맙습니다. intentintegrator.java와 intentresult.java를 살펴 보았습니다. –