Android Question I can not display notifications ...

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,

I have tried on Android 4.2.2 and 4.4.4 and I am no more able to display notifications. What I see is the icon of the application and a sentence from the system. When I click on the notification, I go to the application's details page (from the Applications in the Android Settings).

Dim n as Notification in the Process_Globals

In Main, Activity_Create
B4X:
n.Initialize
n.Icon = "notification"
n.Light = False
n.Sound = False
n.Vibrate = False
n.Number=1
n.AutoCancel = True
n.OnGoingEvent = False
n.Insistent = False
n.SetInfo("Title","Description",Me)

I have tried from a service in Service_Start
B4X:
Service.StartForeground(1, Main.n)

and I even instead tried from the same service in Service_Start
B4X:
Main.n.Notify(1)

The notification's icon is in \Objects\res\drawable.
The Manifest's content is
AddManifestText(
<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="21"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)

SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light")

Please do you see what I do wrong ? Many thanks
 

barx

Well-Known Member
Licensed User
Longtime User
Last issue I saw like this, the icon image was named wrong. What is it's name and is it still there (i.e. read-only)?
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,

Thanks for your information. The icon is read only and still in the folder.
I have checked with another name and I got nothing more. The previous name was really 'notification.png'
Many thanks again
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Hmm, this works for me.
B4X:
'Give this a whirl.
   Dim NotificationInfo As Notification 

'''''''''''''''''''''''''''''''''''''''''''

   NotificationInfo.Initialize
   NotificationInfo.Icon = "notificationicon"
   NotificationInfo.Light = True
   NotificationInfo.Sound = True
   NotificationInfo.Vibrate = False
   NotificationInfo.SetInfo("Test 123", NotificationMessage, Main)
   Service.StartForeground(1, NotificationInfo) 'Start Notification

'''''''''''''''''''''''''''''''''''''''''''

Blah blah blah
   Service.StopForeground(1)'Stop Notification
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello Peter,

Your sample code works correctly. So it gave me the idea to remove the initialization from the Main activity. And it worked.

I wonder if it is the fact to declare the notification from the Main (or perhaps the "Me") that was the reason of the issue. I'll have to do more tests about.

Thanks a lot
 
Upvote 0
Top