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.
Migrate from GoogleAuthUtil and Plus.API
If you integrated with Google Sign-In in the past using GoogleAuthUtil.getToken or Plus.API, you should migrate to the newest Sign-In API for greater security and a better user experience.
Ref: https://developers.google.com/identity/sign-in/android/migration-guide
Also check this out whether it helps
http://www.programcreek.com/java-api-examples/index.php?source_dir=AndroidAppDeployer-master/AndroidAppDeployer/src/com/appjma/appdeployer/service/DownloadService.java
http://www.programcreek.com/java-api-examples/index.php?source_dir=AndroidAppDeployer-master/AndroidAppDeployer/src/com/appjma/appdeployer/receiver/AuthReceiver.java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With