下面列出了com.google.zxing.integration.android.IntentResult#getFormatName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void onScanPerformed(IntentResult scanResult) {
if (scanResult == null || scanResult.getFormatName() == null) {
return; // aborted
}
handleOpenPgp4Fpr(scanResult.getContents());
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==IntentIntegrator.REQUEST_CODE) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (scanResult == null || scanResult.getFormatName() == null) {
return; // aborted
}
String qrRaw = scanResult.getContents();
DcLot qrParsed = dcContext.checkQr(qrRaw);
switch (qrParsed.getState()) {
case DcContext.DC_QR_ACCOUNT:
String domain = qrParsed.getText1();
new AlertDialog.Builder(this)
.setMessage(getString(R.string.qraccount_ask_create_and_login, domain))
.setPositiveButton(R.string.ok, (dialog, which) -> startQrAccountCreation(qrRaw))
.setNegativeButton(R.string.cancel, null)
.setCancelable(false)
.show();
break;
default:
new AlertDialog.Builder(this)
.setMessage(R.string.qraccount_qr_code_cannot_be_used)
.setPositiveButton(R.string.ok, null)
.show();
break;
}
}
}
/**
* This method handles the results of the scan
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null){
if(result.getContents()==null){
Toast.makeText(this, getResources().getText(R.string.error_canceled_scan), Toast.LENGTH_LONG).show();
} else {
qrcodeFormat = result.getFormatName();
qrcode = result.getContents();
if(!qrcode.equals("")){
codeImage.setVisibility(View.VISIBLE);
showQrImage();
mTvFormat.setVisibility(View.VISIBLE);
mLabelInformation.setVisibility(View.VISIBLE);
mLabelFormat.setVisibility(View.VISIBLE);
mTvFormat.setText(qrcodeFormat);
mTvInformation.setText(qrcode);
action_navigation.setVisibility(View.VISIBLE);
if(qrcode.contains("BEGIN:VCARD") & qrcode.contains("END:VCARD")){
action_navigation_web_button.setVisibility(View.GONE);
action_navigation_contact_button.setVisibility(View.VISIBLE);
} else {
action_navigation_contact_button.setVisibility(View.GONE);
action_navigation_web_button.setVisibility(View.VISIBLE);
}
//Check if history is activated
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String history_setting = prefs.getString("pref_history", "");
if(history_setting.equals("false")){
//Don't save QR-Code in history
} else {
addToDatabase(mTvInformation.getText().toString(), mTvFormat.getText().toString());
}
//Automatic Clipboard if activated
Boolean auto_scan = prefs.getBoolean("pref_start_auto_clipboard", false);
if(auto_scan == true){
copyToClipboard(mTvInformation, qrcode, activity);
}
}
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}