如何在将数据插入数据库时​​添加百分比的进度条?

时间:2017-03-11 04:11:29

标签: android android-asynctask android-progressbar

这是我将数据插入数据库的代码。我使用了Asynctask和HTTPUrlConnection。我想实现0% - 100%的进度对话框。反正有吗?我需要它,因为我还有另一个活动,它将在数据库中插入图像和文件。所以我真的必须为此显示一个进度条。

private void registerDeveloper(String acctID, String devName, String devEmail, String devWebsite, String devLogo, String devStatus) {
    class RegisterUser extends AsyncTask<Object, Void, String> {

        RequestHandler ruc = new RequestHandler();
        ProgressDialog loading;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
         //   loading = ProgressDialog.show(getActivity(), "Please Wait", null, true, true);
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            FragmentManager fm = getSupportFragmentManager();
            df_SuccessDevRegistration dialogFragment = new df_SuccessDevRegistration();
            dialogFragment.show(fm, "Account not yet verified.");
        }

        @Override
        protected String doInBackground(Object... params) {

            String uploadImage = getStringImage(bitmap);

            HashMap<String, Object> data = new HashMap<>();
            data.put("acctID", params[0]);
            data.put("devName", params[1]);
            data.put("devEmail", params[2]);
            data.put("devWebsite",params[3] );
            data.put("devLogo", uploadImage);
            data.put("devStatus", params[5]);

            String REGISTER_URL = DataClass.localAddress + "android_php/developer_register.php";
            String result = ruc.sendPostRequest(REGISTER_URL, data);
            return result;

        }


    }

    RegisterUser ru = new RegisterUser();
    ru.execute(acctID, devName, devEmail, devWebsite, devLogo, devStatus);
}

然后是我的PHP代码:

<?php
        require_once('dbconnect.php');

        if($_SERVER['REQUEST_METHOD']=='POST'){

         $acctID = $_POST['acctID'];
         $devName = $_POST['devName'];
         $devEmail = $_POST['devEmail'];
         $devWebsite = $_POST['devWebsite'];
         $devLogo = $_POST['devLogo'];
         $devStatus = $_POST['devStatus'];
         $id = 0;
         $fileName = $devName . '_' . $acctID. '.jpg';
         $devLogoLink = "android_php/dev_logo/$fileName";
         $devLogoLink2 = "../android_php/dev_logo/$fileName";



         $check = mysqli_fetch_array(mysqli_query($con,$sql));
         $sql = "INSERT INTO tbldeveloper (acctID, devName,devEmail,devWebsite,devLogo,devStatus)VALUES('$acctID','$devName','$devEmail','$devWebsite','$devLogoLink','$devStatus')";

        if(mysqli_query($con,$sql))
        {
         file_put_contents($devLogoLink2,base64_decode($devLogo));
         }


         mysqli_close($con);

        }else{
        echo 'error';
        }

0 个答案:

没有答案