我正在尝试触发应用程序要求用户同意应用程序通过 GoogleAuthUtil.getToken() 访问用户数据的窗口。
但是我看不到从 UserRecoverableAuthException 触发的活动。
我已搜索但未找到任何解决此问题的有用帖子。
有人有想法么?(“Shoot2!”被打印出来,但之后 LogCat 中什么也没有发生)。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println("HERE!!!");
System.out.println(CalendarScopes.CALENDAR);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
System.out.println("Hello2!");
String token = GoogleAuthUtil.getToken(EventsActivity.this, "jdoe@gmail.com", "oauth2:" + CalendarScopes.CALENDAR);
System.out.println("token");
System.out.println("Hello3!");
} catch (GooglePlayServicesAvailabilityException playEx) {
System.out.println("Shoot1!");
playEx.printStackTrace();
} catch (UserRecoverableAuthException recoverableException) {
System.out.println("Shoot2!");
Intent recoveryIntent = recoverableException.getIntent();
recoveryIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(Intent.FLAG_FROM_BACKGROUND);
// Use the intent in a custom dialog or just startActivityForResult.
startActivityForResult(recoveryIntent, 99);
} catch (GoogleAuthException authEx) {
System.out.println("Shoot3!");
// This is likely unrecoverable.
authEx.printStackTrace();
} catch (IOException ioEx) {
System.out.println("Shoot4!");
ioEx.printStackTrace();
}
return null;
}
}.execute();