Closed PsyhoLord closed 5 years ago
Hi @PsyhoLord, thanks for the feedback. Can you please clarify exactly what your question(s) is? Are you saying there is missing information in the documentation? Are you seeing any errors?
Finally, I found an issue, after 2 days of the investigation. I made a repository of 2 solutions: 1) Fcm.Xamarin.Android - Firebase notifications for Xamarin Android 2) Xamarin.Android - Azure Notifications Hub for Xamarin Android Xamarin.Android.Summary.docx - my report about this documentation
Commit named: "Fixed Azure Hub notifications" is what is missed in current documentation, why I couldn't send any notification to Android. Also, You can use this code as "NotificationHubs app sample" which are broken.
Missed things: 1) AndroidManifest.xml Before <application android.... Need to insert permissions:
2) Need to add a check for google play services, will prevent a lot of developer issues. Add method: public bool IsPlayServicesAvailable() { int resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.Success) { if (GoogleApiAvailability.Instance.IsUserResolvableError(resultCode)) Log.Debug(TAG, GoogleApiAvailability.Instance.GetErrorString(resultCode)); else { Log.Debug(TAG, "This device is not supported"); Finish(); } return false; }
Log.Debug(TAG, "Google Play Services is available.");
return true;
}
In method OnCreate, after code: if (Intent.Extras != null) { foreach (var key in Intent.Extras.KeySet()) { if (key != null) { var value = Intent.Extras.GetString(key); Log.Debug(TAG, "Key: {0} Value: {1}", key, value); } } } Add: IsPlayServicesAvailable();
Add to MainActivity: variable for channel id internal static readonly string CHANNEL_ID = "my_notification_channel";
3) Into MyFirebaseMessagingService.cs Add usings: using Android.OS; using Android.Support.V4.App; using Build = Android.OS.Build;
Method: SendNotification is using deprecated method new Notification.Builder(this); need to be updated with new one: new NotificationCompat.Builder(this)
Add to construction of notification builder: .SetShowWhen(false) - if remove notification comes to device, but not shown
For new Android (8 and upper version) is required to ser Channel. so after notification builder need to add this lines:
if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { notificationBuilder.SetChannelId(MainActivity.CHANNEL_ID); }
That's all.
Also, you are losing clients with badly documented tutorials. Because this was the case, why my friend told me that ANH (Azure Notification Hub) is not working and he doesn't want to use it. I did not believe him and started to investigate. But in that time other people have feedback - that ANH - is bad. I like how it works, so I will recommend it. But documentation will be good if it will be working and up to date. Thanks
One more: 4) MainActivity.cs, method: OnCreate after line: IsPlayServicesAvailable();
Add: CreateNotificationChannel();
Add method in MainActivity.cs: void CreateNotificationChannel() { if (Build.VERSION.SdkInt < BuildVersionCodes.O) { // Notification channels are new in API 26 (and not a part of the // support library). There is no need to create a notification // channel on older versions of Android. return; }
var channelName = CHANNEL_ID;
var channelDescription = string.Empty;
var channel = new NotificationChannel(CHANNEL_ID, channelName, NotificationImportance.Default)
{
Description = channelDescription
};
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.CreateNotificationChannel(channel);
}
Found on additional testing at Android 8. Pushed change
@PsyhoLord The comments feature of our documentation is intended to enable customers to suggest changes to the docs or ask clarifying questions about the docs. I'm happy to help you resolve issues with the docs, but please refrain from disparaging the product - it's not constructive.
Developers use the service to send billions of notifications per month, so if your friend or you have a problem getting the service to work for you, we can help you do that and update the docs based on what we learned.
The samples and the SDK were just refreshed, so they're up to date and tested. However, I will have the team take a look at your issue and we'll make the necessary doc and sample updates if warranted.
If you're having a problem, please don't just tell us it's not working, explain in detail how it's failing and include the complete text of any error messages plus sample code if possible.
@spelluru can you please take a look at this?
Sorry, have missed repo URL: https://github.com/PsyhoLord/AzureNotificationHub This is a full working sample with Commit named: "Fixed Azure Hub notifications" is what is missed in the current documentation
Also, there is documentation about with report this documentation. I have implemented step-by-step everything from this document and notifications were still not working. All screens are included. Also, sometime before there was a sample project, for now, there is no sample in C#. I have created a sample, working and tested at different devices with different versions of Android. My report: https://github.com/PsyhoLord/AzureNotificationHub/blob/master/Xamarin.Android.Summary.docx
EDIT: Missed things:
AndroidManifest.xml
Before <application android....
Need to insert permissions:
[<] uses-permission android:name="android.permission.INTERNET" /> [<] uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> [<] uses-permission android:name="android.permission.WAKE_LOCK" /> [<]uses-permission android:name="android.permission.GET_ACCOUNTS"/>
[<] -> need to changed to < When I just send without [] - it deletes my text
Final article
Finally, I found an issue, after 2 days of the investigation. I made a repository of 2 solutions:
Fcm.Xamarin.Android - Firebase notifications for Xamarin Android
Xamarin.Android - Azure Notifications Hub for Xamarin Android
Xamarin.Android.Summary.docx - my report about this documentation
https://github.com/PsyhoLord/AzureNotificationHub/blob/master/Xamarin.Android.Summary.docx
https://github.com/PsyhoLord/AzureNotificationHub Commit named: "Fixed Azure Hub notifications" is what is missed in current documentation, why I couldn't send any notification to Android. Also, You can use this code as "NotificationHubs app sample" which are broken.
Missed things:
AndroidManifest.xml
Before <application android....
Need to insert permissions:
Need to add a check for google play services, will prevent a lot of developer issues. Add method: public bool IsPlayServicesAvailable() { int resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.Success) { if (GoogleApiAvailability.Instance.IsUserResolvableError(resultCode)) Log.Debug(TAG, GoogleApiAvailability.Instance.GetErrorString(resultCode)); else { Log.Debug(TAG, "This device is not supported"); Finish(); } return false; }
Log.Debug(TAG, "Google Play Services is available.");
return true;
}
In method OnCreate, after code: if (Intent.Extras != null) { foreach (var key in Intent.Extras.KeySet()) { if (key != null) { var value = Intent.Extras.GetString(key); Log.Debug(TAG, "Key: {0} Value: {1}", key, value); } } } Add: IsPlayServicesAvailable();
Add to MainActivity: variable for channel id internal static readonly string CHANNEL_ID = "my_notification_channel";
Into MyFirebaseMessagingService.cs
Add usings:
using Android.OS;
using Android.Support.V4.App;
using Build = Android.OS.Build;
Method: SendNotification is using deprecated method new Notification.Builder(this); need to be updated with new one: new NotificationCompat.Builder(this)
Add to construction of notification builder: .SetShowWhen(false) - if remove notification comes to device, but not shown
For new Android (8 and upper version) is required to ser Channel. so after notification builder need to add this lines:
if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { notificationBuilder.SetChannelId(MainActivity.CHANNEL_ID); }
That's all.
Sorry, I am not refraining the product, maybe it's just looked like, but this wasn't my target. I like Microsoft product very well, that was the reason to find out why the clean project, step by step is not working. I believed, that Azure Notification Hub cannot be working - it is impossible. I just want to help to make documentation more clear that customers be happier.
@PsyhoLord thanks for your feedback, we'll take a look at what you provided and make the necessary updates to the samples and the docs.
@PsyhoLord there's a bevy of .NET Samples at https://github.com/Azure/azure-notificationhubs-dotnet/tree/master/Samples.
I have prepared document in MS Word, with better formatting about all missings that I have found in documentation (all that I have done to make project working and getting notifications) OneDrive: https://1drv.ms/w/s!AoT9U2Pa3zHNhNtgQ0Pj1zBxecfzpA Git: https://github.com/PsyhoLord/AzureNotificationHub/blob/master/MissingInformation.docx
If it is not clear or needs more details or testing, You are welcome to ask me. Have a good day
@jwargo Thanks, that's great samples. Can you put them to the sector "Overview" at "NotificationHubs app" link as a sample? Will be great.
@PsyhoLord - Thanks very much for the feedback and the sample code. Do you still get the following message when you Test Send a message from the Azure portal? Thanks
"Message was successfully sent, but there were no matching targets."
@PsyhoLord - I have done the steps in the tutorial myself. I could run the application but I didn't see the notification messages on the Galaxy Nexus emulator. I have made changes you noted in the word document and I see the notification now. Here is what I am planning to do:
With my fix, it works too. Thanks for attention, glad for good feedback. It will be great if it will be helpful and working. I still like Microsoft's products, and like when they get better. Have a good day, and thank you
Also will be great if the link to the "NotificationHubs app sample" will target to link that you have provided: https://github.com/Azure/azure-notificationhubs-dotnet/tree/master/Samples/Xamarin/GetStartedXamarinAndroid It will be very helpful. Because it is still : 404 not found.
@PsyhoLord - I have fixed the link in the article and the updated article should go live in 15-30 minutes. However, the repo has old code that uses GCM. I will submit a PR sometime today with the new project files. Thanks.
Also, need to missing instructions here. All that I prepared in doc OneDrive: https://1drv.ms/w/s!AoT9U2Pa3zHNhNtgQ0Pj1zBxecfzpA Git: https://github.com/PsyhoLord/AzureNotificationHub/blob/master/MissingInformation.docx Or maybe review, and leave most important
Without permissions in Manifest - it is not registering at an azure notification hub
@PsyhoLord - Yes. Thanks very much. I used your doc to get it working for me, updated the article, and tested it again. I think we should be good with the article now. The PR into azure-notificationhubs-dotnet repository should be merged soon with the updated sample code.
Great! Have a good day
@PsyhoLord thanks for your detailed feedback and helping us improve our documentation. @spelluru Thanks for updating the documentation.
We will now proceed to close this thread. If there are further questions regarding this matter, please tag me in your reply. We will gladly continue the discussion and we will reopen the issue.
I was implementing a solution, step by step, at clean Xamarin.Android project. Notifications are simply not showing. Used manual for Xamarin Android and FCM only - worked fine. I have mentioned that at FCM solution there is registration to channel at MainActivity.cs in method OnCreate. Maybe I need something same here?
Also, I have tried to implement a solution in a project where FCM solution is, also not working. Maybe I am something missing... At Azure Notification Hub says: send successfully. Looks, that everything is fine.
Maybe in class constants is my mistake: public const string NotificationHubName = "<hub name>"; -> when I put a name of notification hub, like "MyTestHub" (name of a hub that I have entered at azure portal)
That was the reason, that I was asking for a sample in C#. PS sorry for concerning comments last time.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.