Answer the question
In order to leave comments, you need to log in
How to add/remove scanner result from MySQL database?
I have an application that has a "zxing" scanner added to it. I need to add or remove the result of the scanner from the database by clicking on the button. Please tell me how this can be done?
Code of the scanner itself:
public class ScannerActivity extends AppCompatActivity {
static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scanner);
}
/*Запуск сканера qr-кода:*/
public void scanQR(View v) {
try {
/*Запускаем переход на com.google.zxing.client.android.SCAN с помощью intent:*/
Intent intent = new Intent(ACTION_SCAN);
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
} catch (ActivityNotFoundException anfe) {
/*Предлагаем загрузить с Play Market:*/
showDialog(ScannerActivity.this, "Сканнер не найден", "Установить сканер с Play Market?", "Да", "Нет").show();
}
}
/*alert dialog для перехода к загрузке приложения сканера:*/
private static AlertDialog showDialog(final Activity act, CharSequence title,
CharSequence message,CharSequence buttonYes, CharSequence buttonNo) {
AlertDialog.Builder downloadDialog = new AlertDialog.Builder(act);
downloadDialog.setTitle(title);
downloadDialog.setMessage(message);
downloadDialog.setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
/*Ссылка поискового запроса для загрузки приложения:*/
Uri uri = Uri.parse("market://search?q=pname:" + "com.google.zxing.client.android");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
try {
act.startActivity(intent);
} catch (ActivityNotFoundException anfe) {
}
}
});
downloadDialog.setNegativeButton(buttonNo, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
}
});
return downloadDialog.show();
}
/*Обрабатываем результат, полученный от приложения сканера:*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
/*Получаем данные после работы сканера и выводим их в Toast сообщении:*/
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Toast toast = Toast.makeText(this, "Содержание: " + contents + " Формат: " + format, Toast.LENGTH_LONG);
toast.show();
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question