Android Question Firebase Notification

Ale_resource

Member
Licensed User
Hi , i followed the tutorial at https://www.b4x.com/android/forum/t...-messages-firebase-cloud-messaging-fcm.67716/ , but when compile the app i have this error :
1595586448645.png

the manifest is :
Manifest:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
'********* TabStrip ***********************
CreateResource(drawable, background_tab.xml,
<selector xmlns:android="http://schemas.android.com/apk/res/android"
   android:exitFadeDuration="@android:integer/config_shortAnimTime">
  <item android:state_pressed="true" android:drawable="[USER=45325]@Color[/USER]/background_tab_pressed" />
  <item android:state_focused="true" android:drawable="[USER=45325]@Color[/USER]/background_tab_pressed"/>
  <item android:drawable="@android:color/transparent"/>
</selector>)
CreateResource(values, colors.xml,
<resources>
  <color name="background_tab_pressed">#6633B5E5</color>
</resources>)
'******************************************
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)

FirebaseMessaging Service:
#Region  Service Attributes
    #StartAtBoot: False
    
#End Region

Sub Process_Globals
    Private fm As FirebaseMessaging
End Sub

Sub Service_Create
    fm.Initialize("fm")

End Sub

Public Sub SubscribeToTopics
    fm.SubscribeToTopic("general") 'you can subscribe to more topics
End Sub

Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
    Sleep(0)
    Service.StopAutomaticForeground 'remove if not using B4A v8+.
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    Dim n As Notification
    n.Initialize
    n.Icon = "icon"
    n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
    n.Notify(1)
End Sub

Sub Service_Destroy

End Sub

I made all the recommended updates on sdk manager
I also attach the AndroidManifest

what am I doing wrong ?
 

Attachments

  • AndroidManifest.xml
    9.2 KB · Views: 265

Ale_resource

Member
Licensed User
Please copy and paste the error log in text format.
where can I find an error log? in the ide I do not see anything .... the app crashes and I do not see anything

if i remove this line from manifest
s:
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
the app start and work , else the app crash
immediately
 
Last edited:
Upvote 0

Ale_resource

Member
Licensed User
I tried to remove this line from the manifest
B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
and now the app starts but i have this log :
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
firebasemessaging_service_create (java line: 173)
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.resource.cassa. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@19.3.0:184)
at com.google.firebase.messaging.FirebaseMessaging.getInstance(com.google.firebase:firebase-messaging@@20.1.2:1)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.Initialize(FirebaseNotificationsService.java:97)
at com.resource.cassa.firebasemessaging._service_create(firebasemessaging.java:173)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at com.resource.cassa.firebasemessaging.onCreate(firebasemessaging.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3558)
at android.app.ActivityThread.-wrap4(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1812)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
 
Last edited:
Upvote 0

Bladimir Silva Toro

Active Member
Licensed User
Longtime User
Hello @Ale_resource

Look at the following link and follow the steps: https://www.b4x.com/android/forum/threads/solved-firebasenotifications-error-in-b4a.116626/

The solution to the error was the SDK, for this download the following:

1. Android SDK Command line tools. https://dl.google.com/android/repository/sdk-tools-windows-4333796.zip
2. Required resources. https://b4xfiles-4c17.kxcdn.com/b4a/resources.zip

After downloading and unzipping DOES NOT update the SDK

You inform me if the error is solved
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I tried to remove this line from the manifest
These lines should not be remove.
B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
Can you upload the zip file of your project?
 
Upvote 0

asales

Expert
Licensed User
Longtime User
You tested this code on a device with which android version?
I have similar problem (other lib) in devices with < Android 5.0
 
Upvote 0
Top