Main > Forum > 1C:Enterprise Platform > 1C:Enterprise. Mobile platform > Android push notification not received

Forum

Search UsersRules
Android push notification not received
#1
Active user
Points:: 0
Joined:: Mar 29, 2016

Hi,

I working on push notification. My code is:

Mobile;

//managed application module

Code
Procedure OnStart()
   UpdateClientID();
   
   AttachIdleHandler("Connectable_UpdateFollowingID", 7200);
   #If MobileAppClient Then
      DeliverableNotifications.AttachNotificationHandler("Plugin_ProcessingNotifications");
   #EndIf   
EndProcedure

Procedure Connectable_UpdateFollowingID() Export
   UpdateClientID();
EndProcedure

Procedure UpdateClientID()
   #If MobileAppClient Then
      mProjectNumber = CommonCallServer.GetProjectNumber();
      If IsBlankString(mProjectNumber) Then
         Return;      
      EndIf; 
      
      Try
         SubscriberID = DeliverableNotifications.ReceiveNotificationSubscriberID(mProjectNumber);
      Except
         Message(ErrorDescription());
         Return;
      EndTry;
      
      mQueryOptions = New Structure("ServerAddress, NameBase, ClientID");
      // указываем IP Сервера, он может быть как локальный, так и нет
      mQueryOptions.ServerAddress = "192.168.0.14";
      // имя базы, под которым она была опубликована на вэб сервере
      // о том, как выполнить публикацию информации в Интернете информации предостаточно
      mQueryOptions.NameBase      = "GELAL";
      mQueryOptions.ClientID = SubscriberID;
      
      CommonCallServer.SendIDToServer(mQueryOptions);
   #EndIf
EndProcedure

Procedure Plugin_ProcessingNotifications(Notification, IsLocal, IsShow) Export
   // просто сообщим тест пуша
   Message(Notification.Text);
   #If MobileAppClient Then
      MultimediaTools.PlaySoundAlert(SoundAlert.Default,True);
      Noti = New DeliverableNotification;
      Noti.Title   = Notification.Text;
      Noti.Text   = Notification.Text;
      Noti.SoundAlert = SoundAlert.Default;
      DeliverableNotifications.AddLocalNotification(Noti);
   #EndIf
EndProcedure


It is working. my mobile device get id from firebase and update server constant is clientID.

Than, i was try send a deliverablenotification on server to mobile device.

Server;

Code
&AtServer
Procedure OnCreateAtServer(Cancel, StandardProcessing)
   ThisForm.ServerKey = "AAAA5L5rYdQ:APA91bEY0GG6FZB2GCW3OwnUhBtAREB65pghyZvc9UKJC64IyOenBJFTDYVqwVBw7T2POQg-E_Vd37eALjkKqb9gKWlPlxCOtO2BQa82DXEnDJSR-qnonyFiC8aLXTCx4rAmTrkjpLdA";
   ThisForm.Başlık = "AA";
   ThisForm.Mesaj = "AAA";
EndProcedure

&AtClient
Function DeSerialize(Data, ConversionType = Undefined)
   XMLReader = New XMLReader;
   XMLReader.SetString(Data);
   mReadXML = XDTOSerializer.ReadXML(XMLReader, ConversionType);
   XMLReader.Close();
   Return mReadXML;
EndFunction

&AtServerNoContext
Function GetClientID()
   Return Constants.ClientID.Get().Get();
EndFunction
 
&AtClient
Procedure Gönder(Command)
   Notification      = New DeliverableNotification;
    Notification.Title   = Başlık;
   Notification.Text   = Mesaj;
   Notification.SoundAlert = SoundAlert.Default;
   pXML = DeSerialize(GetClientID());
   Notification.Recipients.Add(pXML);
   DeliverableNotificationSend.Send(Notification, ServerKey);
EndProcedure

&AtClient
Procedure OnOpen(Cancel)
   ThisForm.ClientID = DeSerialize(GetClientID()).DeviceID;
EndProcedure



This code is working. Not give error. But notification not received my mobile device.

My versions are:
Mobile device: Android 5.1
Mobile App: 8.3.12.67

Server: 8.3.12.1567

How can i fix this issue? Please help me.

Profile
#2
Interested
Points:: 0
Joined:: Dec 4, 2017

Dear Hüseyin Çağrı Bayraktar,

To be able to find out why your code works not as you expect it to do, we need to get a configuration to try the code at.

Could you please send as a sample configuration (.*dt) for that purpose?

Best regards,
Vladimir Gurov

Profile
#3
Active user
Points:: 0
Joined:: Mar 29, 2016

Dear Vladimir,

Can you send your email address?

Profile
#4
Interested
Points:: 0
Joined:: Dec 4, 2017

int@1c.ru

Profile
#5
Active user
Points:: 0
Joined:: Mar 29, 2016

I will send now.

Profile
#6
Interested
Points:: 0
Joined:: Dec 4, 2017

Dear Hüseyin Çağrı Bayraktar,

We are still investigating the samples you sent us.

Meanwhile we recommend you to add the 5th parameter to the call to the DeliverableNotificationSend.Send() method in your code.

The parameter (DeliverableNotificationSendIssuesInformation) is to get information from 1C:Enterprise platform about issues that occurred when sending notifications via the call.

<<
<DeliverableNotificationSendIssuesInformation> (optional)

Type: Array.
Contains the details of deliverable notification sending issues. It is an array of elements of DeliverableNotificationSendingIssueInformation type.
>>

Best regards,
Vladimir Gurov

Profile
#7
Active user
Points:: 0
Joined:: Mar 29, 2016

Hi Vladimir,

Ok. I will try that 5th parameter.

I'm waiting to hear from you.

Profile
#8
Active user
Points:: 0
Joined:: Mar 29, 2016

Hi,

I tried the method you said. I'm adding screenshots step by step.

Image 1: https://yadi.sk/i/KmDRx7PzpRXoQg

Image 2: https://yadi.sk/i/QoKnsgfta5VrpQ

Image 3: https://yadi.sk/i/yDYH6smoWvONFA

Image 4: https://yadi.sk/i/lh-5y9tyaRzWHQ

Image 5: https://yadi.sk/i/IBKwoEMqg7QCxg

Image 6: https://yadi.sk/i/B0U6n2JmERQlww

Image 7: https://yadi.sk/i/j_choJvsZMUyGA

Image 8: https://yadi.sk/i/bF7jkWW5sEnDDw

Image 9: https://yadi.sk/i/FalBXm8vOSbuqQ

Image 10: https://yadi.sk/i/EnE4WS6KPCtRog

Profile
#9
Interested
Points:: 0
Joined:: Dec 4, 2017

Dear Hüseyin Çağrı Bayraktar,

In your code, for push notifications, you use FCM (Firebase Cloud Messaging).

To be able to correctly use FCM, we recommend you to switch to 1C:Enterprise platform 8.3.13.

Best regards,
Vladimir Gurov

Profile
#10
Active user
Points:: 0
Joined:: Mar 29, 2016

Dear Vladimir,

1C:Enterprise platform for PC or Mobile?

I will update photos now.

Profile
#11
Active user
Points:: 0
Joined:: Mar 29, 2016

Dear Vladimir,

Thanks!

I will try on 1C:Enterprise 8.3.13.1513 PC Platform and 8.3.12.64 Mobile Platform that code.

My android version: Android 8.0.0
My android device: Huawei bla-l09 (huawei mate 10 pro)

When app is opened notification is received!

But when app is not opened my mobile device give that error:

Code
java.lang.RuntimeException: Unable to start receiver com.e1c.mobile.PushNotificationReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.e1c.mobile cmp=com.e1c.mobile/.PushNotificationService (has extras) }: app is in background uid UidRecord{b0a3730 u0a164 RCVR idle procs:1 seq(0,0,0)}
   at android.app.ActivityThread.handleReceiver(ActivityThread.java:3705)
   at android.app.ActivityThread.-wrap18(Unknown Source:0)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1979)
   at android.os.Handler.dispatchMessage(Handler.java:108)
   at android.os.Looper.loop(Looper.java:166)
   at android.app.ActivityThread.main(ActivityThread.java:7425)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.e1c.mobile cmp=com.e1c.mobile/.PushNotificationService (has extras) }: app is in background uid UidRecord{b0a3730 u0a164 RCVR idle procs:1 seq(0,0,0)}
   at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1701)
   at android.app.ContextImpl.startService(ContextImpl.java:1657)
   at android.content.ContextWrapper.startService(ContextWrapper.java:644)
   at android.content.ContextWrapper.startService(ContextWrapper.java:644)
   at android.support.v4.content.WakefulBroadcastReceiver.a(Unknown Source:23)
   at com.e1c.mobile.PushNotificationReceiver.onReceive(Unknown Source:19)
   at android.app.ActivityThread.handleReceiver(ActivityThread.java:3695)
   ... 8 more



I'm adding my screenshots.

Image 1: https://yadi.sk/i/dFg_8yVE-qs6Ng (PC)

Image 2: https://yadi.sk/i/AloD3G16FL45ZQ (Mobile Device)

Image 3: https://yadi.sk/i/wIAybMthkNwVxg (Mobile Device)

Image 4: https://yadi.sk/i/xARCpWFsof7bUA (Mobile Device)

Image 5: https://yadi.sk/i/Xpibb5b7x-M3wQ (Mobile Device) (Error)

Image 6: https://yadi.sk/i/3t8v3jaGHY5IiQ (Mobile Device) (Error)

Profile
#12
Interested
Points:: 0
Joined:: Dec 4, 2017

Dear Hüseyin Çağrı Bayraktar,

Could you please try this code on 1C:Enterprise platform 8.3.13 and 1C:Enterprise mobile platform 8.3.13, and let us know the results?

Best regards,
Vladimir Gurov

Profile
#13
Active user
Points:: 0
Joined:: Mar 29, 2016

Dear Vladimir,

Yes, Its working on 1C:Enterprise platform 8.3.13 and 1C:Enterprise mobile platform 8.3.13.45.

My device is android 8.0.0

Thanks :)

Profile
#14
Interested
Points:: 0
Joined:: Dec 4, 2017

Dear Hüseyin Çağrı Bayraktar,

It's great to hear that.

Best regards,
Vladimir Gurov

Profile
#15
Active user
Points:: 0
Joined:: Mar 29, 2016

Hi,

Its not working on 1C:Enterprise platform 8.3.13.1926 and 1C:Enterprise mobile platform 8.3.15.59.

My device is android 9.1.0

Why? Please help me!

My code example:

Code
Notification      = New DeliverableNotification;
         Notification.Title   = "A";
         Notification.Text   = "A";
         Notification.Data    = "A";
         Notification.SoundAlert = SoundAlert.Default;
         pXML = GetMobilCihazID();
         If pXML <> "" Then
            Notification.Recipients.Add(pXML);
            pErrors = New Array;
            DeliverableNotificationSend.Send(Notification, Constants.FirebasePushNotificationServerKey.Get(), , False, pErrors);
            If pErrors.Count() > 0 Then
               fReturn.Mesaj = "(FCM ERRORS)";
            Else
               fReturn.Durum = True;
            EndIf;
                        EndIf;

Profile
#16
Administrator
Points:: 0
Joined:: Oct 3, 2019

Dear Hüseyin Çağrı Bayraktar,

please send a description of the error that occurs with this.

Profile
#17
Active user
Points:: 0
Joined:: Mar 29, 2016

Dear Aleksandr,

Error description: GCM üzerinden mesaj gönderimi 1 hata ile tamamlandı: Error=DeprecatedEndpoint

And Error screenshot:

Please fix that error.

My code:

Code
pErrors = New Array;
               DeliverableNotificationSend.Send(Notification, Constants.FirebasePushNotificationServerKey.Get(), , False, pErrors);
               If pErrors.Count() > 0 Then
                  fReturn.Mesaj = "OOpps! Hata oluştu! (FCM ERRORS)";
               Else
                  fReturn.Durum = True;
               EndIf;

Profile
#18
Administrator
Points:: 0
Joined:: Oct 3, 2019

Dear Hüseyin Çağrı Bayraktar,

thank you for your message.

We will pass the error information to the configuration developers.

Profile
#19
Administrator
Points:: 0
Joined:: Oct 3, 2019

Dear Hüseyin Çağrı Bayraktar,

did you migrate your GCM projects to the Firebase?

How to do project migration is described here: https://developers.google.com/cloud-messaging/android/android-migrate-fcm

Profile
#20
Active user
Points:: 0
Joined:: Mar 29, 2016

I have already created my application on Firebase. I didn't create it with GCM. I'm waiting for the problem to be fixed.

I use the notification mechanism with more than 1,000 people.

Profile
#21
Administrator
Points:: 0
Joined:: Oct 3, 2019

Hi Hüseyin Çağrı Bayraktar!

There really is a problem.

When you receive the recipient ID on the mobile device:

SubscriberID = DeliverableNotifications.ReceiveNotificationSubscriberID ("YourProjectNumber") -

back you get an object of type "DeliverableNotificationSubscriberID". One of the properties of this object "SubscriberType" must be set to FCM, but 1C instead returns GCM.

As a result, you send the wrong SubscriberID value to the server and therefore an error occurs when sending push notifications.

We will fix this bug as quickly as possible in the next releases of the 1C platform.

Now I can offer you to generate SubscriberID on the server at the time of sending push notifications itself. To do this, change the value of "SubscriberType" from "GCM" to "FCM".

Hope the following code helps you figure out how to do this:


Code
Function DeSerialize(Data, ConversionType = Undefined)
   
   XMLReader = New XMLReader;
   
   XMLReader.SetString(Data);
   mReadXML = XDTOSerializer.ReadXML(XMLReader, ConversionType);
   
   XMLReader.Close();
   
   Return mReadXML;
   
EndFunction

Function GetClientID()
   
   Return DeSerialize(Constants.ClientID.Get()).DeviceID;
   
EndFunction

Function ReceiveRecipient()
   
   DeviceID = GetClientID();
   
   xdtoSubscriber = XDTOFactory.Create(XDTOFactory.Type("http://v8.1c.ru/8.3/data/ext","DeliverableNotificationSubscriberID"));
    xdtoSubscriber.DeviceID = DeviceID;
   
   xdtoSubscriber.SubscriberType = XDTOFactory.Create(XDTOFactory.Type("http://v8.1c.ru/8.3/data/ext","DeliverableNotificationSubscriberType"), "FCM");
   
   NewSerializerXDTO = New XDTOSerializer(XDTOFactory);
   
   Subscriber = NewSerializerXDTO.ReadXDTO(xdtoSubscriber);
        
    Return Subscriber;
   
EndFunction

&AtClient
Procedure SendPush(Command)

   ServerKey = "_YOUR_SERVER_KEY_";

   Notification         = New DeliverableNotification;
   
        Notification.Title      = "Some text";
   Notification.Text      = "Some text";
   Notification.Data      = "Some text";
   Notification.SoundAlert         = SoundAlert.Default;
   
   Notification.Recipients.Add(ReceiveRecipient());
   
   pErrors = New Array;
   
   DeliverableNotificationSend.Send(Notification, ServerKey,,, pErrors);   
   
   If pErrors.Count() > 0 Then
      
   Else
      
   EndIf;   
   
EndProcedure

Profile
#22
Active user
Points:: 0
Joined:: Mar 29, 2016

Dear Aleksandr Biryukov,

You are a great man. I solved the problem just like you told me. I owe you Turkish delight.

Profile
#23
Administrator
Points:: 0
Joined:: Oct 3, 2019

Hi Hüseyin Çağrı Bayraktar!

That sounds great!

And I'm going to Turkey soon :-)

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.