T
T
TILLhen2018-05-03 07:19:50
MySQL
TILLhen, 2018-05-03 07:19:50

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();











            }
        }
    }
}

After scanning, an Activity should open, in which we must, by clicking on the button, add the result to the MySQL database, or delete it from the database.
5aea8ddcb0d3a031087626.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yan-s, 2018-05-03
@TILLhen

Create a table to store the results.
When scanning, send a save request.
When you click on the delete button, send a request for deletion.
www.sql.ru/docs/mysql/rus_ref

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question