Sync contacts android with remote database





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I try to synchronize the contacts of the mobile device with a database in this case Postgresql, the way I do it does not seem to be the most convenient.



    public void sincronizarcontactos(){

// Se tiene permiso
final String projeccion = new String{ContactsContract.CommonDataKinds.Phone._ID,ContactsContract.Data.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER};
String selectionClause = ContactsContract.Data.MIMETYPE + "='" +
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND "
+ ContactsContract.CommonDataKinds.Phone.NUMBER + " IS NOT NULL";
String sortOrder = ContactsContract.Data.DISPLAY_NAME + " ASC";

final Cursor c = getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
projeccion,
selectionClause,
null,
sortOrder);

HashSet<String> normalizedNumbersAlreadyFound = new HashSet<>();
int indexOfNormalizedNumber = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER);
progreso= ProgressDialog.show(SincronizarActivity.this, "", "Sincronizando...", true);

int o=0;

while(c.moveToNext()){
o++;
progreso.show();
String email=c.getString(0).replace(" ","_");
String normalizedNumber = c.getString(indexOfNormalizedNumber);
if(normalizedNumbersAlreadyFound.add(normalizedNumber)){
String urlinsert="http://192.168.1.33/Agenda/insert_persona.php?name="+c.getString(0)+
"&city=Paute&email="+email+"@gmail.com&phone="+c.getString(1)+"&mobile="+c.getString(2);

JsonObjectRequest solicitud = new JsonObjectRequest(urlinsert,null, new Response.Listener<JSONObject>(){
@Override
public void onResponse(JSONObject datos) {
Toast.makeText(SincronizarActivity.this, "Guardado", Toast.LENGTH_SHORT).show();
}
},new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error) {
progreso.dismiss();
Toast.makeText(SincronizarActivity.this, "Tuvimos un problema de conexión...", Toast.LENGTH_SHORT).show();
}
});
VolleyRP.addToQueue(solicitud,request,this,volley);
}

if (o==projeccion.length){
progreso.dismiss();
}

}
progreso.dismiss();
Toast.makeText(SincronizarActivity.this, "Se han sicronizado sus contactos...", Toast.LENGTH_SHORT).show();
c.close(); }


As I say it does not seem to me to be the most correct way, I would like you to help me to get them to synchronize automatically, example as in the photo ...



Imagen de referencia










share|improve this question





























    0















    I try to synchronize the contacts of the mobile device with a database in this case Postgresql, the way I do it does not seem to be the most convenient.



        public void sincronizarcontactos(){

    // Se tiene permiso
    final String projeccion = new String{ContactsContract.CommonDataKinds.Phone._ID,ContactsContract.Data.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER};
    String selectionClause = ContactsContract.Data.MIMETYPE + "='" +
    ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND "
    + ContactsContract.CommonDataKinds.Phone.NUMBER + " IS NOT NULL";
    String sortOrder = ContactsContract.Data.DISPLAY_NAME + " ASC";

    final Cursor c = getContentResolver().query(
    ContactsContract.Data.CONTENT_URI,
    projeccion,
    selectionClause,
    null,
    sortOrder);

    HashSet<String> normalizedNumbersAlreadyFound = new HashSet<>();
    int indexOfNormalizedNumber = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER);
    progreso= ProgressDialog.show(SincronizarActivity.this, "", "Sincronizando...", true);

    int o=0;

    while(c.moveToNext()){
    o++;
    progreso.show();
    String email=c.getString(0).replace(" ","_");
    String normalizedNumber = c.getString(indexOfNormalizedNumber);
    if(normalizedNumbersAlreadyFound.add(normalizedNumber)){
    String urlinsert="http://192.168.1.33/Agenda/insert_persona.php?name="+c.getString(0)+
    "&city=Paute&email="+email+"@gmail.com&phone="+c.getString(1)+"&mobile="+c.getString(2);

    JsonObjectRequest solicitud = new JsonObjectRequest(urlinsert,null, new Response.Listener<JSONObject>(){
    @Override
    public void onResponse(JSONObject datos) {
    Toast.makeText(SincronizarActivity.this, "Guardado", Toast.LENGTH_SHORT).show();
    }
    },new Response.ErrorListener(){
    @Override
    public void onErrorResponse(VolleyError error) {
    progreso.dismiss();
    Toast.makeText(SincronizarActivity.this, "Tuvimos un problema de conexión...", Toast.LENGTH_SHORT).show();
    }
    });
    VolleyRP.addToQueue(solicitud,request,this,volley);
    }

    if (o==projeccion.length){
    progreso.dismiss();
    }

    }
    progreso.dismiss();
    Toast.makeText(SincronizarActivity.this, "Se han sicronizado sus contactos...", Toast.LENGTH_SHORT).show();
    c.close(); }


    As I say it does not seem to me to be the most correct way, I would like you to help me to get them to synchronize automatically, example as in the photo ...



    Imagen de referencia










    share|improve this question

























      0












      0








      0








      I try to synchronize the contacts of the mobile device with a database in this case Postgresql, the way I do it does not seem to be the most convenient.



          public void sincronizarcontactos(){

      // Se tiene permiso
      final String projeccion = new String{ContactsContract.CommonDataKinds.Phone._ID,ContactsContract.Data.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER};
      String selectionClause = ContactsContract.Data.MIMETYPE + "='" +
      ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND "
      + ContactsContract.CommonDataKinds.Phone.NUMBER + " IS NOT NULL";
      String sortOrder = ContactsContract.Data.DISPLAY_NAME + " ASC";

      final Cursor c = getContentResolver().query(
      ContactsContract.Data.CONTENT_URI,
      projeccion,
      selectionClause,
      null,
      sortOrder);

      HashSet<String> normalizedNumbersAlreadyFound = new HashSet<>();
      int indexOfNormalizedNumber = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER);
      progreso= ProgressDialog.show(SincronizarActivity.this, "", "Sincronizando...", true);

      int o=0;

      while(c.moveToNext()){
      o++;
      progreso.show();
      String email=c.getString(0).replace(" ","_");
      String normalizedNumber = c.getString(indexOfNormalizedNumber);
      if(normalizedNumbersAlreadyFound.add(normalizedNumber)){
      String urlinsert="http://192.168.1.33/Agenda/insert_persona.php?name="+c.getString(0)+
      "&city=Paute&email="+email+"@gmail.com&phone="+c.getString(1)+"&mobile="+c.getString(2);

      JsonObjectRequest solicitud = new JsonObjectRequest(urlinsert,null, new Response.Listener<JSONObject>(){
      @Override
      public void onResponse(JSONObject datos) {
      Toast.makeText(SincronizarActivity.this, "Guardado", Toast.LENGTH_SHORT).show();
      }
      },new Response.ErrorListener(){
      @Override
      public void onErrorResponse(VolleyError error) {
      progreso.dismiss();
      Toast.makeText(SincronizarActivity.this, "Tuvimos un problema de conexión...", Toast.LENGTH_SHORT).show();
      }
      });
      VolleyRP.addToQueue(solicitud,request,this,volley);
      }

      if (o==projeccion.length){
      progreso.dismiss();
      }

      }
      progreso.dismiss();
      Toast.makeText(SincronizarActivity.this, "Se han sicronizado sus contactos...", Toast.LENGTH_SHORT).show();
      c.close(); }


      As I say it does not seem to me to be the most correct way, I would like you to help me to get them to synchronize automatically, example as in the photo ...



      Imagen de referencia










      share|improve this question














      I try to synchronize the contacts of the mobile device with a database in this case Postgresql, the way I do it does not seem to be the most convenient.



          public void sincronizarcontactos(){

      // Se tiene permiso
      final String projeccion = new String{ContactsContract.CommonDataKinds.Phone._ID,ContactsContract.Data.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER};
      String selectionClause = ContactsContract.Data.MIMETYPE + "='" +
      ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND "
      + ContactsContract.CommonDataKinds.Phone.NUMBER + " IS NOT NULL";
      String sortOrder = ContactsContract.Data.DISPLAY_NAME + " ASC";

      final Cursor c = getContentResolver().query(
      ContactsContract.Data.CONTENT_URI,
      projeccion,
      selectionClause,
      null,
      sortOrder);

      HashSet<String> normalizedNumbersAlreadyFound = new HashSet<>();
      int indexOfNormalizedNumber = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER);
      progreso= ProgressDialog.show(SincronizarActivity.this, "", "Sincronizando...", true);

      int o=0;

      while(c.moveToNext()){
      o++;
      progreso.show();
      String email=c.getString(0).replace(" ","_");
      String normalizedNumber = c.getString(indexOfNormalizedNumber);
      if(normalizedNumbersAlreadyFound.add(normalizedNumber)){
      String urlinsert="http://192.168.1.33/Agenda/insert_persona.php?name="+c.getString(0)+
      "&city=Paute&email="+email+"@gmail.com&phone="+c.getString(1)+"&mobile="+c.getString(2);

      JsonObjectRequest solicitud = new JsonObjectRequest(urlinsert,null, new Response.Listener<JSONObject>(){
      @Override
      public void onResponse(JSONObject datos) {
      Toast.makeText(SincronizarActivity.this, "Guardado", Toast.LENGTH_SHORT).show();
      }
      },new Response.ErrorListener(){
      @Override
      public void onErrorResponse(VolleyError error) {
      progreso.dismiss();
      Toast.makeText(SincronizarActivity.this, "Tuvimos un problema de conexión...", Toast.LENGTH_SHORT).show();
      }
      });
      VolleyRP.addToQueue(solicitud,request,this,volley);
      }

      if (o==projeccion.length){
      progreso.dismiss();
      }

      }
      progreso.dismiss();
      Toast.makeText(SincronizarActivity.this, "Se han sicronizado sus contactos...", Toast.LENGTH_SHORT).show();
      c.close(); }


      As I say it does not seem to me to be the most correct way, I would like you to help me to get them to synchronize automatically, example as in the photo ...



      Imagen de referencia







      android postgresql web-services synchronization contacts






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 19:36









      Wilson CajisacaWilson Cajisaca

      1




      1
























          1 Answer
          1






          active

          oldest

          votes


















          0














          The query code looks ok, I think the question you're asking is "how do I run a contact sync operation integrated into Android's ecosystem".



          The answer would by to create a Contacts SyncAdapter, see my answer to a similar question here: https://stackoverflow.com/a/44566012/819355






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53487880%2fsync-contacts-android-with-remote-database%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The query code looks ok, I think the question you're asking is "how do I run a contact sync operation integrated into Android's ecosystem".



            The answer would by to create a Contacts SyncAdapter, see my answer to a similar question here: https://stackoverflow.com/a/44566012/819355






            share|improve this answer




























              0














              The query code looks ok, I think the question you're asking is "how do I run a contact sync operation integrated into Android's ecosystem".



              The answer would by to create a Contacts SyncAdapter, see my answer to a similar question here: https://stackoverflow.com/a/44566012/819355






              share|improve this answer


























                0












                0








                0







                The query code looks ok, I think the question you're asking is "how do I run a contact sync operation integrated into Android's ecosystem".



                The answer would by to create a Contacts SyncAdapter, see my answer to a similar question here: https://stackoverflow.com/a/44566012/819355






                share|improve this answer













                The query code looks ok, I think the question you're asking is "how do I run a contact sync operation integrated into Android's ecosystem".



                The answer would by to create a Contacts SyncAdapter, see my answer to a similar question here: https://stackoverflow.com/a/44566012/819355







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 27 '18 at 8:50









                marmormarmor

                19.6k885129




                19.6k885129
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53487880%2fsync-contacts-android-with-remote-database%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    To store a contact into the json file from server.js file using a class in NodeJS

                    Redirect URL with Chrome Remote Debugging Android Devices

                    Dieringhausen