我正在尝试使用GoogleAuthUtil获取Oauth令牌。getToken,并使用Async task将任务作为单独的线程运行。
LogCat输出显示异步任务所需的参数已传递给它。(在本例中为上下文、电子邮件和作用域)。
下面是Async Task的代码:
public class GetUsernameTask extends AsyncTask<Void, Void, Void>{
Activity mActivity;
String mScope;
String mEmail;
GetUsernameTask(Activity activity, String Email, String Scope){
Log.i(TAG,"Local variables are set from received arguments");
this.mActivity = activity;
this.mScope = Scope;
this.mEmail = Email;
}
@Override
protected Void doInBackground(Void... arg0) {
try {
Log.i(TAG,"fetchToken is called");
String token = fetchToken();
mToken = token;
//Stuff to do with the token comes here - (Consider sending it to the backend;
} catch(IOException e){
}
return null;
}
LogCat还告诉我fetchToken()方法被调用。下面是fetchToken()
的代码private String fetchToken() throws IOException {
try {
Log.i(TAG,"attempts to getToken");
return GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
} catch (UserRecoverableAuthException userRecoverableException){
Log.i(TAG,"recoverable Exception Found");
//((MainActivity) mActivity).handleException(userRecoverableException);
} catch (GoogleAuthException fatalException){
Log.i(TAG,"fataException found");
}
return null;
}
调试模式打开前的最后一条logcat消息来自Log。i(TAG,"attempts to getToken"); .
我不知道如何从这里进行,或者如何在这种特殊情况下进行调试。任何下一步的方向都很棒。
android manifest文件中缺少一个元数据标签。我在manifest文件
中添加了以下代码<meta-data
android:name = "com.google.android.gms.version"
android:value="@integer/google_play_services_version"
/>
在我添加了打印建议的RuntimeException后,错误被指出。下面是我为RuntimeException
添加的代码catch (RuntimeException e){
Log.i(TAG, "RuntimeException caught");
e.printStackTrace();
}