Click here to Skip to main content
15,867,308 members
Home / Discussions / Android
   

Android

 
QuestionQR camera scan with android phone using C# Pin
A.Shoman15-Jul-19 21:04
A.Shoman15-Jul-19 21:04 
AnswerRe: QR camera scan with android phone using C# Pin
Richard MacCutchan15-Jul-19 21:15
mveRichard MacCutchan15-Jul-19 21:15 
Questiondownload sound file in android webview Pin
Member 1450174330-Jun-19 23:00
Member 1450174330-Jun-19 23:00 
QuestionRe: download sound file in android webview Pin
David Crow3-Jul-19 4:11
David Crow3-Jul-19 4:11 
AnswerRe: download sound file in android webview Pin
Member 145017433-Jul-19 4:27
Member 145017433-Jul-19 4:27 
QuestionCan't make charge with stripe in android Fire base Pin
Saboor880220-Jun-19 6:21
Saboor880220-Jun-19 6:21 
SuggestionRe: Can't make charge with stripe in android Fire base Pin
David Crow21-Jun-19 3:08
David Crow21-Jun-19 3:08 
QuestionAll record from SQLite DB is not inserting properly by using PHP and Android. Loop is not working. Pin
PRASANTA KUMAR BISWAS5-May-19 19:33
PRASANTA KUMAR BISWAS5-May-19 19:33 
--Android Code
--============

<pre>private class UploadData extends AsyncTask<String, Void, String>
    {
        @Override
        protected void onPreExecute()
        {
            progressDialog.setMessage("Wait !!! Transferring SQLite Data into SQL Server DB.");
            progressDialog.setIndeterminate(false);
            progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progressDialog.setCancelable(false);
            progressDialog.show();
        }

        @Override
        protected void onPostExecute(String result)
        {
            progressDialog.dismiss();

            AlertDialog YesNo1 = DialogYesNo();
            YesNo1.setMessage("Hh Count Tablet: " + HhTablet + " , Hh Count Server: " + HhServer + "\n" + " -- has been transferred to SQL server DB !!! ");
            YesNo1.setCancelable(false);
            YesNo1.show();

            HhServer = 0;
        }

        @Override
        protected String doInBackground(String... params)
        {
            String result = "";
            httpclient = new DefaultHttpClient();
            httppost = new HttpPost("http://172.16.15.13/testing/datasync.php"); // make sure the url is correct.

            try
            {
                try
                {
                    cursor = ConnectionDB.SelectRecord("Select HH,PartM,GISID,Mohalla from HH");
                    HhTablet = cursor.getCount();

                    if (cursor != null)
                    {
                        cursor.moveToFirst();

                        while (!cursor.isAfterLast())
                        {
                            for (int k = 0; k < HhTablet; k++)
                            {
                                //Add data
                                //========
                                nameValuePairs = new ArrayList<NameValuePair>(4);

                                // Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar
                                //==============================================================================================================================
                                nameValuePairs.add(new BasicNameValuePair("HH", cursor.getString(cursor.getColumnIndex("HH"))));
                                nameValuePairs.add(new BasicNameValuePair("PartM", cursor.getString(cursor.getColumnIndex("PartM"))));
                                nameValuePairs.add(new BasicNameValuePair("GISID", cursor.getString(cursor.getColumnIndex("GISID"))));
                                nameValuePairs.add(new BasicNameValuePair("Mohalla", cursor.getString(cursor.getColumnIndex("Mohalla"))));
                                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                                HhServer = HhServer + 1;
                            }

                            //Execute HTTP Post Request
                            //=========================
                            ResponseHandler<String> responseHandler = new BasicResponseHandler();
                            String responseBody = httpclient.execute(httppost, responseHandler);

                            // JSON Parse
                            //============
                            JSONObject json = new JSONObject(responseBody);
                            JSONArray jArray = json.getJSONArray("posts");
                            ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

                            for (int i = 0; i < jArray.length(); i++)
                            {
                                HashMap<String, String> map = new HashMap<String, String>();
                                JSONObject e = jArray.getJSONObject(i);
                                String s = e.getString("post");
                                JSONObject jObject = new JSONObject(s);

                                map.put("HH", jObject.getString(cursor.getString(cursor.getColumnIndex("HH"))));
                                map.put("PartM", jObject.getString(cursor.getString(cursor.getColumnIndex("PartM"))));
                                map.put("GISID", jObject.getString(cursor.getString(cursor.getColumnIndex("GISID"))));
                                map.put("Mohalla", jObject.getString(cursor.getString(cursor.getColumnIndex("Mohalla"))));
                                mylist.add(map);
                                cursor.moveToNext();
                            }
                        }
                    }
}
                catch (Exception ex)
                {
                    ex.printStackTrace();
                }
                finally
                {
                    cursor.close();
                }
}
            catch (Exception ex)
            {
                ex.printStackTrace();
            }
            return result;
        }
    }


--PHP code
--==========

<?php
include ("dbconnection.php"); 

$json = file_get_contents('php://input');
$obj = json_decode($json);

$HH=$_POST[HH];
$PartM=$_POST[PartM];
$GISID=$_POST[GISID];
$Mohalla=$_POST[Mohalla];

//First need to delete from database by TABID
//===========================================
//$recdel = "DELETE From HH"; 
//$stmtdel = $conn->query( $recdel );  
//===========================================

//Then need to insert
//===================

//$recdel = "SELECT COUNT(*) FROM HH"; 
//$stmtdel = $conn->query( $recdel ); 

//if ($stmtdel > 0) 
//{
	//$query = "UPDATE HH SET `HH` = '$HH',`PartM` = '$PartM',`GISID` = '$GISID',`Mohalla` = '$Mohalla' WHERE `HH` = '$HH'";   
	//$stmt = $conn->query( $query );
//}
//else
//{
	$query = "INSERT INTO HH(HH,PartM,GISID,Mohalla) VALUES ('$HH','$PartM','$GISID','$Mohalla')";   
	$stmt = $conn->query( $query );
//}
	
	if ($query) 
	{
        $response["success"] = 1;
        $response["message"] = "Record is successfully created.";
        echo json_encode($response);
    } 
	else 
	{
        $response["success"] = 0;
        $response["message"] = "Sorry! An error occurred.";
        echo json_encode($response);
    }
	$posts = array(1);
    header('Content-type: application/json');
    echo json_encode(array('posts'=>$posts));
	
$stmt = null;   
$conn = null; 
?>


modified 6-May-19 6:12am.

SuggestionRe: I am unable to send SQLite data(multiple record) to SQL server 2005 database by using PHP and Android Pin
Richard MacCutchan5-May-19 21:55
mveRichard MacCutchan5-May-19 21:55 
GeneralRe: I am unable to send SQLite data(multiple record) to SQL server 2005 database by using PHP and Android Pin
PRASANTA KUMAR BISWAS5-May-19 23:41
PRASANTA KUMAR BISWAS5-May-19 23:41 
GeneralRe: I am unable to send SQLite data(multiple record) to SQL server 2005 database by using PHP and Android Pin
Richard MacCutchan5-May-19 23:51
mveRichard MacCutchan5-May-19 23:51 
SuggestionRe: All record from SQLite DB is not inserting properly by using PHP and Android. Loop is not working. Pin
Richard Deeming8-May-19 1:34
mveRichard Deeming8-May-19 1:34 
Questionno database data after depolyment Pin
Wiep Corbier29-Apr-19 21:54
Wiep Corbier29-Apr-19 21:54 
AnswerRe: no database data after depolyment Pin
Richard MacCutchan29-Apr-19 22:43
mveRichard MacCutchan29-Apr-19 22:43 
GeneralRe: no database data after depolyment Pin
Wiep Corbier29-Apr-19 23:16
Wiep Corbier29-Apr-19 23:16 
GeneralRe: no database data after depolyment Pin
Wiep Corbier30-Apr-19 7:29
Wiep Corbier30-Apr-19 7:29 
GeneralRe: no database data after depolyment Pin
Mycroft Holmes30-Apr-19 12:31
professionalMycroft Holmes30-Apr-19 12:31 
GeneralRe: no database data after depolyment Pin
Wiep Corbier1-May-19 8:10
Wiep Corbier1-May-19 8:10 
Questionandroid Pin
Alazar yikunuamlak11-Apr-19 19:04
Alazar yikunuamlak11-Apr-19 19:04 
AnswerRe: android Pin
Richard MacCutchan11-Apr-19 20:31
mveRichard MacCutchan11-Apr-19 20:31 
QuestionHow to get URL from a browser(Chrome, Firefox…) while sharing highlighted text on react native app? Pin
Member 1418193013-Mar-19 22:56
Member 1418193013-Mar-19 22:56 
AnswerRe: payment for add some control code into an existing apk, opticalelec at yandex.com Pin
Eddy Vluggen2-Mar-19 0:36
professionalEddy Vluggen2-Mar-19 0:36 
QuestionAndroid SD card Pin
AlainP15-Feb-19 23:03
AlainP15-Feb-19 23:03 
AnswerRe: Android SD card Pin
David Crow18-Feb-19 4:04
David Crow18-Feb-19 4:04 
QuestionBuilding website and android Apps Pin
Member 1414695911-Feb-19 8:24
Member 1414695911-Feb-19 8:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.