android - Importing gmail contacts using GoogleAuthUtil -


i'm trying add import contacts gmail account function in android app. first problem access token gmail. i've found there googleauthutil class can me it.
here code:

private void importcontactsfromgmail() {     showprogressdialog();     gettokentask gettokentask = new gettokentask();     gettokentask.execute();     string token = "";     try {         token = gettokentask.get();     } catch (exception e) {         e.printstacktrace();     }     system.out.println(token);     hideprogressdialog(); }  private class gettokentask extends asynctask<void, void, string> {      @override     protected string doinbackground(void... params) {         string token = "";         try {             token = googleauthutil.gettoken(activity, <my_gmail_account>, "https://www.google.com/m8/feeds/");         } catch (exception e) {             e.printstacktrace();           }         return token;     } } 

now after calling googleauthutil.gettoken app freezes(no errors in logcat). stuck , need help.
wrong code? maybe should import contacts in other way?

not sure if related calling .get() method on main thread not correct because blocking method.

what if use asynctask in way?

public class mainactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         new gettokentask().execute();     }      static class gettokentask  extends asynctask<void, void, string> {          @override         protected string doinbackground(void... unused) {             string token = "";             try {                 token = googleauthutil.gettoken(activity, <my_gmail_account>, "https://www.google.com/m8/feeds/");             } catch (exception e) {                 e.printstacktrace();               }              return token;         }          @override         protected void onpostexecute(string token) {             toast.maketext(mainactivity.this, token, toast.length_short).show();         }     }  } 

(i wrote without compiling it, maybe needs adjusted)


Comments

Popular posts from this blog

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -