microsoft / appcenter-sdk-cordova

App Center Preview SDK for Cordova
http://appcenter.ms
MIT License
50 stars 27 forks source link

Push notification didn't show on device with Android #95

Closed slawomir-marek closed 5 years ago

slawomir-marek commented 5 years ago

Description

Some time ago we updated cordova-plugin-appcenter-push from version 0.3.4 to 0.3.5. After that we noticed that we've had problems with receiving push notifications on devices with Android system. On devices with iOS everything worked as expected. When we replaced plugin with previous version everything worked perfect.

Repro Steps

In our case to reproduce this bug we have to: 1) Install (or upgrade to latest version which supports push notification) our application 2) Open application first time - this action will register unique installation identifier on our backend (appCenter.getInstallId()) 3) Create some push notification on our backend or directly in AppCenter (it doesn't matter that we send this notification to all registered devices or defined devices list) 4) Push notification doesn't occur on device 5) Open/close our app few times 6) Create push notification once again 7) Push notification occurs on device

Details

  1. Which SDK version are you using? 0.3.5
  2. Which OS version did you experience the issue on? Android 8, Android 9
  3. What version of Cordova, Cordova platforms, Cocoapods, and Ruby are you using? Cordova version 8.0.0
  4. What device version did you see this error on? Were you using a simulator or a physical device? Nokia 7Plus, Huawei P10 Lite
  5. What third party plugins are you using? cordova-android-firebase-gradle-release 3.0.0 "cordova-android-firebase-gradle-release" cordova-android-play-services-gradle-release 3.0.0 "cordova-android-play-services-gradle-release" cordova-plugin-actionsheet 2.3.3 "ActionSheet" cordova-plugin-app-version 0.1.9 "AppVersion" cordova-plugin-appcenter-analytics 0.3.5 "App Center Analytics for Cordova" cordova-plugin-appcenter-push 0.3.5 "App Center Push for Cordova" cordova-plugin-appcenter-shared 0.3.5 "App Center shared code for Cordova" cordova-plugin-background-mode 0.7.2 "BackgroundMode" cordova-plugin-browsertab 0.2.0 "cordova-plugin-browsertab" cordova-plugin-camera 4.0.3 "Camera" cordova-plugin-cocoapod-support 1.6.0 "Cordova CocoaPods Dependency Support" cordova-plugin-compat 1.2.0 "Compat" cordova-plugin-contacts 3.0.1 "Contacts" cordova-plugin-device 2.0.2 "Device" cordova-plugin-dialogs 2.0.1 "Notification" cordova-plugin-inappbrowser 3.0.0 "InAppBrowser" cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard" cordova-plugin-ionic-webview 3.1.2 "cordova-plugin-ionic-webview" cordova-plugin-ms-adal 0.10.1 "ADAL for Cordova" cordova-plugin-network-information 2.0.1 "Network Information" cordova-plugin-splashscreen 5.0.2 "Splashscreen" cordova-plugin-statusbar 2.4.2 "StatusBar" cordova-plugin-whitelist 1.3.3 "Whitelist" cordova-sqlcipher-adapter 0.2.1 "Cordova sqlcipher adapter" uk.co.workingedge.phonegap.plugin.launchnavigator 5.0.4 "Launch Navigator"
Jamminroot commented 5 years ago

Hey, @slawomir-marek, thanks for getting in touch. Give me some time to investigate this behaviour, I'll keep you updated in this thread,

Jamminroot commented 5 years ago

Are you trying to send push notification while app is on the background, or in the foreground? Is it only the first launch of the app that reproduces the problem, or every launch (without reinstalls)?

slawomir-marek commented 5 years ago

We tried to send push notification when app was off or when it was in background. We're sending notification through AppCenter API. After every attempt notifications were on the list in AppCenter but their status was showed as 0/x where x is the number of recipients. There was no error.

I was in contact with AppCenter support and they wrote me, that it could be related with delay in propagation of deviceID throug AppCenter servers. But after that I found that this bug occurs only with latest version of plugin (0.3.5) and only on Android devices.

Described problem has always occurred after app installation. Then user had to turn off/on app few times. After that action he was able to receive push notifications. If he tried to reinstall app the same problem has occurred once again.

We also tried to wait some time after installation and first launch to check if is it related with delay in propagation of device ID. In our case we still hasn't been able to receive push notification.

Jamminroot commented 5 years ago

We've checked your scenario on newly created app, and couldn't reproduce your problem - push notification appeared correctly while app is either in the background or closed.

Can you enable verbose logging for device with a problem, and provide logcat output after running through the following scenario: 1) Launch app 2) Minimize app (send it to background) 3) Send push notification while app is in the background To enable verbose logging, please add the following line to <AppFolder>\platforms\android\app\src\main\java\com\microsoft\azure\mobile\cordova\AppCenterShared.java, inside configureAppCenter() method before AppCenter.configure() is called:

AppCenter.setLogLevel(2);

That would help us understand what is missing and figure out how can we help you resolve SDK problem. Thanks in advance.

larcho commented 5 years ago

I'm having the same issue, and it seems related to AppCenter not initializing Firebase properly. I noticed this when looking at Logcat:

FirebaseInitProvider: FirebaseApp initialization unsuccessful

After adding Firebase to the projects .gradle file it worked (adding the dependencies and applying the plugin at the end of the gradle file). Seems odd though, considering documentation states that AppCenter includes Firebase in the plugin.

Jamminroot commented 5 years ago

@larcho can you share repro steps so that I can confirm the problem? Thanks in advance

larcho commented 5 years ago

Sure, this is a snippet of my config.xml:

<engine name="ios" spec="^5.0.1" />
<engine name="android" spec="^8.0.0" />
<engine name="browser" spec="^6.0.0" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<plugin name="cordova-plugin-appcenter-analytics" spec="~0.3.4" />
<plugin name="cordova-plugin-appcenter-crashes" spec="~0.3.4" />
<plugin name="cordova-plugin-appcenter-push" spec="~0.3.4" />
<plugin name="cordova-plugin-code-push" spec="~1.11.19" />
<plugin name="cordova-plugin-file" spec="~4.3.3" />
<plugin name="cordova-plugin-file-transfer" spec="~1.6.3" />
<plugin name="cordova-plugin-zip" spec="~3.1.0" />

I then proceed with "cordova prepare" (I before delete the folders platforms and plugin to assure a clean prepare) and tested the APK first with "cordova build android". This is when I noticed that I wasn't receiving push notifications anymore. I then proceeded with opening the generated Android Studio project and set AppCenter's verbose log to inspect for issues. That's when I noticed that Firebase wasn't being initialized correctly.

I have a feeling it has to do with the additional AppCenter .gradle file not being correctly executed.

Jamminroot commented 5 years ago

We still can't reproduce the problem. @larcho, can you kindly run through the list below, and correct me on what I have probably missed? Thanks in advance.

Here is what I did (pelase ignore unnecessary steps, since I wanted to be 100% sure I tried to reproduce problem): 1) Init app like this:

cordova create ctapp com.demo.ctapp ctapp
cd ctapp
cordova platform add android
cordova platform add ios
cordova plugin add cordova-plugin-appcenter-analytics
cordova plugin add cordova-plugin-appcenter-push

2) Following this instruction downloaded and copied google-services.json to root project folder (NOT platform-specific) and added

<resource-file src="google-services.json" target="app/google-services.json" />

to config.xml's android platform section 3) Following instructions from appcenter.ms portal added APP_SECRET param to config.xml's android platform section. 4) Added plugins you mentioned in this post. At this point, this is what my config.xml looked like:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.demo.ctapp" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>ctapp</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <plugin name="cordova-plugin-appcenter-analytics" spec="~0.3.4" />
    <plugin name="cordova-plugin-appcenter-crashes" spec="~0.3.4" />
    <plugin name="cordova-plugin-appcenter-push" spec="~0.3.4" />
    <plugin name="cordova-plugin-code-push" spec="~1.11.19" />
    <plugin name="cordova-plugin-file" spec="~4.3.3" />
    <plugin name="cordova-plugin-file-transfer" spec="~1.6.3" />
    <plugin name="cordova-plugin-zip" spec="~3.1.0" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <resource-file src="google-services.json" target="app/google-services.json" />
        <preference name="APP_SECRET" value="<SECRET>" />
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

5) Removed platforms and plugins folders from project 6) Run cordova prepare 7) Run cordova run android to test on physical device 8) Waited for app to launch, then minimized it with home button 8) Tested push from portal, verified push received.

slawomir-marek commented 5 years ago

Hi

Sorry for delay. I followed your instruction:

  1. Enabled verbose logging AppCenter.setLogLevel(2);
  2. Enabled loging into file adb logcat | grep -i 'AppCenter' > logs.txt
  3. Installed and launched app
  4. Sent app to background
  5. Created push notification

As I expected I didn't received push notification. After second restart I started receiving notifications.

I added file with logs.

AppCenterLogs.txt

Jamminroot commented 5 years ago

Hey, @slawomir-marek I think the issue is caused by the initial app start ran with debugger attached - for pushes to work normally, Firebase would require one launch without debugger. Might aswell be related to instant run being turned on - if ran through Android Studio. Can you confirm or dismiss those points?

slawomir-marek commented 5 years ago

@Jamminroot this bug was found in production application - so without any attached debuggers. And I didn't run app through Android Studio.

guperrot commented 5 years ago

One thing from the logs you shared:

07-23 15:09:04.057 23125 23225 D AppCenterPush: Using old Firebase methods.

I do not get that in a blank application with either 0.3.4, 0.3.5 or 0.3.6 appcenter plugins. The first run problem is something that we addressed recently and should have been present in 0.3.6 and probably 0.3.5 too.

In your case the first run does not send the push token in that setup because of a mismatch of firebase version apparently, thus we get token only via polling and not via callbacks, which works only from second run onward.

As for the second run it tried to but you got 503 errors in the logs because there was a problem in production at that time.

The 503 errors should be resolved if you try now but that leaves the problem of the first run.

Can you go to platforms/android folder and run ./gradlew :app:dependencies (maybe redirect output to a file) and upload the results?

Can you try on 0.3.6 plugin as well?

MatkovIvan commented 5 years ago

Hi @slawomir-marek, we haven't heard from you in a while so I'm closing this issue. Feel free to reopen this issue if it isn't resolved or you have additional questions.

shnaz commented 5 years ago

@slawomir-marek, I am having the exact same problem in a Xamarin.Forms app. We also experience that the android device has to restart in order for it to receive notifications. Out of curiosity, did you manage to solve this issue in your app?

russelarms commented 5 years ago

@shnaz Could you open a new issue here and include all the information in the template? Otherwise, it's difficult for us to test your exact scenario.

shnaz commented 5 years ago

@russelarms Ofc. I will do that as well.

But if @slawomir-marek wants to share his solution, it would benefit anyone else who stumbles upon this issue.

Best regards

marciordonez commented 5 years ago

Same problem here. After send push in AppCenter, the result column in push notifications page, shows for a moment "QUEUED" and after one minute shows "0 / 0 sent".... I'm using Xamarin.Forms

image

AnastasiaKubova commented 5 years ago

Hi @marciordonez ! Thank you for contacting us! Could you open a new issue here and include all the information in the template? Otherwise, it's difficult for us to test your exact scenario.

slawomir-marek commented 5 years ago

HI @marciordonez I didn't solve this issue. I left this problem because of other important topics in my project. Today I returned to that and I tried to install latest version of plugin (0.4.1). Nothing changed - problem still occurs.

AnastasiaKubova commented 4 years ago

Hi @slawomir-marek ! Have you had a chance to take a look at this answer?