Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hub.register(token, tag); throws exception if already registered #22

Open
hangryfabian opened this issue Apr 9, 2019 · 4 comments
Open

Comments

@hangryfabian
Copy link

hub.register() crashes the second time (i.e. you cannot run this or change the registered tag every time on launch).
This used to work in a previous version, where we can re-register a new tag when a user logged out of their account and registered/signed in with a new one.

We are handling this by storing the FCM tokens, but this function should be failing gracefully, or calling a update registration with new tag instead. It shouldn't throw a random exception.

Thanks!

@brannon
Copy link
Contributor

brannon commented Apr 10, 2019

Hi, can you provide any more detail? Maybe a callstack or simple code sample?
Thanks!

@hangryfabian
Copy link
Author

//issue: fcm push messaging is working properly. hub.register works the first time you launch the app. Every subsequent time it crashes. In a previous version we would call hub.reg with a new tag and it would 'update' the registration automatically (that's how we do it on iOS too)

CODE:

public class MyInstanceIDService extends FirebaseMessagingService {

@Override
public void onNewToken(String s) {
	super.onNewToken(s);

	Mediator.getInstance().fcmToken = s;
	MyInstanceIDService.RegisterFCM(getApplicationContext());
}

private static void RegisterFCM(Context context)
{
	NotificationHub hub = new NotificationHub(Constants.getAzureHubname(), Constants.getAzureHubListenAccess(), context);

	String token = Mediator.getInstance().fcmToken;
	if (token == null || token.length() == 0 )
		return;

	String regId = null;

	try 
	{
		String tag = "user_" + Mediator.getInstance().getTheUser().userid;
		regId = hub.register(token, tag).getRegistrationId(); //works the first time we reg, crashes on subsquent calls
		Utilities.log(regId);

	} catch (Exception e) {
		//e.getmessage() is null
		//stack output below
	}
}

}

STACK
stack trace = android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1513)
java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:117)
java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:105)
java.net.InetAddress.getAllByName(InetAddress.java:1154)
com.android.okhttp.Dns$1.lookup(Dns.java:39)
com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:198)
com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:146)
com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:88)
com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:190)
com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:142)
com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:104)
com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:392)
com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:325)
com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:470)
com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:26)
com.microsoft.windowsazure.messaging.Connection.executeRequest(Connection.java:213)
com.microsoft.windowsazure.messaging.Connection.executeRequest(Connection.java:172)
com.microsoft.windowsazure.messaging.Connection.executeRequest(Connection.java:132)
com.microsoft.windowsazure.messaging.NotificationHub.refreshRegistrationInformation(NotificationHub.java:297)
com.microsoft.windowsazure.messaging.NotificationHub.registerInternal(NotificationHub.java:391)
com.microsoft.windowsazure.messaging.NotificationHub.register(NotificationHub.java:144)
singletons.MyInstanceIDService.RegisterFCM(MyInstanceIDService.java:138)
singletons.MyInstanceIDService.access$000(MyInstanceIDService.java:51)
singletons.MyInstanceIDService$1.onSuccess(MyInstanceIDService.java:197)
singletons.MyInstanceIDService$1.onSuccess(MyInstanceIDService.java:187)
com.google.android.gms.tasks.zzn.run(Unknown Source:4)
android.os.Handler.handleCallback(Handler.java:873)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:214)
android.app.ActivityThread.main(ActivityThread.java:6981)
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)

@kingbin
Copy link

kingbin commented Apr 17, 2019

I'm seeing an error with a similar call to hub.register(token) as well. Not sure if it's related to this issue.

I'm seeing "com.microsoft.windowsazure.messaging.NotificationHubUnauthorizedException: Unauthorized" returned from "return registerInternal(registration);" of notification-hubs-android-sdk-0.6/NotificationHub.java

This was working previously.

@aziztitu
Copy link
Contributor

@hangryfabian We were not able to reproduce this issue on our end. Are you still experiencing this issue on the new version of the SDK?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants