LoginSignup
0
0

More than 1 year has passed since last update.

ファイル送信するまでは、アプリから出しませんよ。Android(java)

Last updated at Posted at 2022-11-17

仕組み

Andoridアプリから、データをサーバー(Apache)へ送り、PHPが基幹システムへ送り出す処理を行ったら、Androidさんありがとう、お疲れ様です。

画像

コード Main

MainActivity.java

  /**
     *  ヘッダー ボタン 処理
     *
     * @param item
     * @return
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {

            case R.id.menu_top_btn :
                //------- ボタンを押した後の処理
                Flg_Send_SELECT();

                if(Send_data_Flg.equals("0") || Send_data_Flg == null) {
                    /**
                     * 一度も送信されていないので エラーを返す
                     */
                    Allahto_Dailog_Send_error();

                } else {
                    /**
                     *  アプリ終了 処理 起動
                     */
                    Allahto_Dailog_01();
                }

                break;

電源ボタンをタップしたら Flg_Send_SELECT() 処理が走る

・フラグを取りにいってもらっています。

MainActivity.java
 /***
     *     Flg_Table ===== Send_data_Flg 取得
     */
    private void Flg_Send_SELECT() {

        TestOpenHelper helper = new TestOpenHelper(getApplicationContext());
        SQLiteDatabase Flg_db_Send = helper.getReadableDatabase();

        Cursor cursor = null;

        try {

            cursor = Flg_db_Send.rawQuery("select Send_data_Flg from Flg_Table", null);

            if(cursor != null && cursor.getCount() > 0) {

                if(cursor.moveToFirst()) {
                    Send_data_Flg = cursor.getString(0);
                }

            } else {
                Send_data_Flg = "0";
                return;
            }


        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if(Flg_db_Send != null) {
                Flg_db_Send.close();
            }
        }

    } // ---------------- END Flg_Send_SELECT

フラグが 0 か null の場合 Allahto_Dailog_Send_error()

・アプリからでちゃダメですよ。

MainActivity.java
private void Allahto_Dailog_Send_error() {

        //------- タイトル
        TextView titleView;
        // アクティビティ名を入れる
        titleView = new TextView(MainActivity.this);
        titleView.setText("ファイル送信エラー");
        titleView.setTextSize(20);
        titleView.setTextColor(Color.WHITE);
        titleView.setBackgroundColor(getResources().getColor(R.color.red));
        titleView.setPadding(20,20,20,20);
        titleView.setGravity(Gravity.CENTER);

        //-------- アラートログの表示 開始 ----------
        AlertDialog.Builder bilder = new AlertDialog.Builder(MainActivity.this);

        /**
         *  ダイアログの項目セット
         */
        //------- タイトルセット
        bilder.setCustomTitle(titleView);

        //------- メッセージセット
        bilder.setMessage("ファイル送信を行ってから、アプリケーションを終了してください。");

        bilder.setNegativeButton("アプリケーションへ戻る", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

                return;

            }
        });

        AlertDialog dialog = bilder.create();
        dialog.show();

        //********* ボタン いいえ **********
        dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(Color.parseColor("#B20000"));
        //   dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setBackgroundColor(getResources().getColor(R.color.red));

    } //-------------- Allahto_Dailog_Send_error  END

フラグがありの場合は、お疲れ様でした。Allahto_Dailog_01()

MainActivity.java

 /**
     *  アラートダイアログ 表示
     */
    private void Allahto_Dailog_01() {

        //------- タイトル
        TextView titleView;
        // アクティビティ名を入れる
        titleView = new TextView(MainActivity.this);
        titleView.setText("アプリケーションの終了");
        titleView.setTextSize(20);
        titleView.setTextColor(Color.WHITE);
        titleView.setBackgroundColor(getResources().getColor(R.color.menu_color));
        titleView.setPadding(20,20,20,20);
        titleView.setGravity(Gravity.CENTER);

        //-------- アラートログの表示 開始 ----------
        AlertDialog.Builder bilder = new AlertDialog.Builder(MainActivity.this);

        /**
         *  ダイアログの項目セット
         */
        //------- タイトルセット
        bilder.setCustomTitle(titleView);

        //------- メッセージセット
        bilder.setMessage("お疲れ様でした。アプリケーションを終了しますか?(作業データは全て削除されます)");

        bilder.setNegativeButton("終了する", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

                Sned_Table_Data_Delete(); // 送信テーブル &  グラフテーブル データ削除

                Flg_Table_Delete(); // フラグテーブル データ削除
            }
        });

        bilder.setPositiveButton("終了しない", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

                //******** 終了しない *********
                //  再度ログインできるように、フラグを false にする。
                app_finish_flag = false;
                return;
            }
        });

        AlertDialog dialog = bilder.create();
        dialog.show();

        //******************************************* ボタン 配色 変更
        //********* ボタン はい **********
        dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.parseColor("#FF4081"));
        //   dialog.getButton(AlertDialog.BUTTON_POSITIVE).setBackgroundColor(getResources().getColor(R.color.red));

        //********* ボタン いいえ **********
        dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(Color.parseColor("#FF4081"));
        //   dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setBackgroundColor(getResources().getColor(R.color.red));

    } //-------------- Allahto_Dailog_01  END

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0