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

Upgrade to lastest android sdk #37

Open
Gilberto-Pavanelli-Jr opened this issue Mar 10, 2021 · 5 comments
Open

Upgrade to lastest android sdk #37

Gilberto-Pavanelli-Jr opened this issue Mar 10, 2021 · 5 comments

Comments

@Gilberto-Pavanelli-Jr
Copy link

I am trying to upgrade to lastest android sdk.

I am facing some deprecated functions and get this exception.

Java.Lang.NoSuchMethodException Message=getToken []

Very clear, but i am stucked in how to get token

 public void OnSuccess(Java.Lang.Object result)
        {
            DeviceInstallationService.Token = result.Class.GetMethod("getToken").Invoke(result).ToString();
        }
@jonathan-caddy
Copy link

I needed to add the following to the OnCreate method

if (DeviceInstallationService.NotificationsSupported)
{
  FirebaseInstallations.GetInstance(Firebase.FirebaseApp.Instance).GetId().AddOnSuccessListener(this);
}

Then ensure the MainActivity class implemented IOnSuccessListener

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, IOnSuccessListener

Then adjust the listener method as it looks like it now just returns the token string

public void OnSuccess(Java.Lang.Object result)
{
  DeviceInstallationService.Token = result.ToString();
}

@kiamajuliet
Copy link

Error:
Default FirebaseApp is not initialized in this process. Make sure to call FirebaseApp.initializeApp(Context) first

Getting this error when using the above solution. Tried the below two ways to initialise it but no luck

  • FirebaseApp.InitializeApp(Application.Context)
  • FirebaseApp.InitializeApp(this);

Please advice

@Leonsito
Copy link

Hi,

I managed to update this part to the new Firebase, following @jonathan-caddy solution.

In the OnCreate method in MainActivity.cs it should be:

if (DeviceInstallationService.NotificationsSupported)
{
     FirebaseMessaging.Instance.GetToken().AddOnSuccessListener(this);
}

This way you will get the token that is the FCM PNS Handle, which we need to register to Azure Notification Hub.

@robintschroeder
Copy link

I am experiencing the same problem @kiamajuliet describes. Any resolution for this?

@Rob97
Copy link

Rob97 commented Nov 12, 2022

@robintschroeder I wrote out my complete solution to the bugs I faced while using the documentation here:

https://github.com/MicrosoftDocs/azure-dev-docs/issues/929

Let me know if it helps.

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

6 participants