Android Question NB6 Notification to take the user to the AppPage in PlayStore

Anser

Well-Known Member
Licensed User
Longtime User
Hi,

I am on the process of changing my app's FCM Notifications from NotificationBuilder to the new NB6 from B4A

To inform my app user regarding the release of a new version, I used to send notification to the user. When the user clicks on the notification, the user will be taken to my App's page on the Google PlayStore.

The code that I used with the BarX's NotificationBuilder library was as follows

B4X:
Dim market As Intent, uri As String
uri="market://details?id=com.myapp.publicapp"
market.Initialize(market.ACTION_VIEW,uri)
     
nb.setActivity(market)
nb.setParentActivity(HomePage)
nb.Notify(nNotificationCount)

The equivalent code that I tried to get the same done using NB6 is as follows. Unfortunately it is not working.
B4X:
Dim market As Intent, uri As String
uri="market://details?id=com.myapp.publicapp"
market.Initialize(market.ACTION_VIEW,uri)
     
nb.Build(cSubject,cMsg,"",market).Notify(nNotificationCount)

When I receive an FCM message on the device, on the LOG I see the following error message

After accept
** Receiver (firebasemessaging) OnReceive **
** Service (firebasemessaging) Start **
nb6_createintent (java line: 262)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:90)
at com.myapp.publicapp.nb6._createintent(nb6.java:262)
at com.myapp.publicapp.nb6._build(nb6.java:165)
at com.myapp.publicapp.fcmnotificationsnew._processnotifications(fcmnotificationsnew.java:536)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1154)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Class.getName()' on a null object reference
at android.content.ComponentName.<init>(ComponentName.java:131)




Any idea what could be wrong here. The message is reaching the device, but unable to dismiss the message by swiping. At the same time, see the above error in the LOG.

I would also like to know the equivalent of BarX's following code
B4X:
nb.setActivity(Offers)
nb.setParentActivity(HomePage)

What the above code does is as follows. Once the user clicks on the Notification the user is taken to the Activity named "Offers". Once the user press the back key from the "Offers" page, the user will be taken to the "HomePage" activity ie the Parent Activity.

Any help will be appreciated
 
Last edited:

Anser

Well-Known Member
Licensed User
Longtime User
I followed the Activity_Resume in the NB6 example and it is working fine to handle PlayStore via Notiifcation.

Another problem identified is described below.

Whenever I send FCM Notification, on the device I receive 2 notifications.

  • One is the real notification with all the content that I send. Perfect
  • The second one appears with just the app name, it is not dismissable by swiping. To remove this notification, either I will have to restart the device or uninstall the app
Any hint what could be the reason of this second unwanted notification reaching the device ?

Whenever FCM message reaches the device, I call a Service to handle FCM Messages. For eg in firebaseMessaging Service
B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
'   Log("Message arrived")
'   Log($"Message data: ${Message.GetData}"$)

    CallSubDelayed2(FcmNotifications,"ProcessNotifications",Message)
  
End Sub

In the FcmNotifications service I call the NB6 as follows
B4X:
Small_Icon = LoadBitmapResize(File.DirAssets, "applogo.png", 24dip, 24dip, False)
  
nb.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(Small_Icon)
nb.LargeIcon( LoadBitmapResize(File.DirAssets, "applogo.png", 256dip, 256dip, True)   )

'From the Message identfy the notification type

If Message.GetData.ContainsKey("NotficationTag")    Then
    cNotficationTag = Message.GetData.Get("NotficationTag")
End If

nb.Build(cSubject, cMsg, cNotficationTag, TheActivity).Notify(nNotificationCount)
nNotificationCount = nNotificationCount + 1
StopService("") 'Not sure whether this line is really required or not

Any help will be appreciated
 
Upvote 0
Top