I have a background service that calls GoogleAuthUtl.getTokenWithNotification
and it works properly but I'm trying to implement the callback portion of this function and that isn't working properly.
I've implemented a broadcast receiver and added it to the manifest, I also have an activity in my app. Below are the relevant pieces of code.
GoogleAuthUtil.getTokenWithNotification
GoogleAuthUtil.getTokenWithNotification(this.getContext(), account, "oauth2:" + GmailScopes.GMAIL_SEND, null, new Intent(AuthReceiver.AUTH_INTENT));
AuthReceiver
public class AuthReceiver extends BroadcastReceiver
{
public final static String AUTH_INTENT = "com.testoauth.AUTH_INTENT";
public AuthReceiver()
{
}
@Override
public void onReceive(Context context, Intent intent)
{
Log.d("RECEIVER", "Received Auth broadcast.");
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
}
AndroidManifest
<receiver android:name=".AuthReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="com.testoauth.AUTH_INTENT" />
</intent-filter>
</receiver>
I have no clue why it is not receiving the broadcast. I don't see any exceptions in the logs and no indication that the receiver was called at all, it won't even break on a breakpoint when debugging. Am I doing something incorrectly?
EDIT
I'm using min sdk 16 and target sdk 25
From the GoogleAuthUtil.getTokenWithNotification API documentation:
This method is specifically provided for background tasks. In the event of an error that needs user intervention, this method takes care of pushing relevant notification. After the user addresses the notification, the callback is broadcasted. If the user cancels then the callback is not fired.
The callback is not fired regardless of the user canceling or not. Aside from the ActivityManager
saying the notification has been displayed (Displayed com.google.android.gms/.auth.uiflows.gettoken.GetTokenActivity
), there is no indication that the specified broadcast intent (in this case com.testoauth.AUTH_INTENT
) has been sent in the logs. The "Received Auth broadcast." message is also absent from the logs.
The included SDK example of this functionality (<android-sdk>/extras/google/google_play_services/samples/auth/gau
) doesn't even work.
It doesn't appear that anyone can give a proper answer to this question; plenty of absolutely great suggestions on how to work around the issue but nothing answering the actual question. I've come to the conclusion that this must be a bug in either Android or the Google Play Services. Unfortunately I've reported this issue to both the Android issue tracker and the Google Play Services support forum... Both of which point the finger at each other and refuse to even look at the issue.