I implemented PushApps Android SDK.
All is well and working, but I want to create a notification by myself without using:
PushManager.buildNotification(intent.getExtras(), context,
NOTIFICATION_ID, R.drawable.notification_icon,
notificationIntent);
specific - I want to show a custom layout using the data received in the
intent.getExtras()
Thanks!
In order to show your own custom notification, you can take control over the PushAppsMessage interface. By doing that, you can show your own custom message with special layouts and more!. Checkout this article - How To Create Android Push Notifications With Custom View?.
Related
I'm using PlayerNotificationManager for displaying playback notifications in my application. Everything is working fine but I want to add my application's logo in the notification with custom fonts.
I changed the play & pause buttons on the notification by adding drawables.xml. But can't find a way to change the font.
So, how can I change the default notification layout and characteristics that Exoplayer provides?
Edit:
I have seen this issue on Github which says that we need to extend PlayerNotificationManager in order to use custom layout. But I can't seem to get it working.
Here is my code:
private void setPlayerNotificationManager(Player player) {
playerNotificationManager = new PlayerNotificationManager(context, "123", 1234, mediaDescriptionAdapter);
playerNotificationManager.setUseNavigationActions(false);
playerNotificationManager.setUsePlayPauseActions(true);
playerNotificationManager.setRewindIncrementMs(0);
playerNotificationManager.setFastForwardIncrementMs(0);
//playerNotificationManager.setColor(Color.GREEN);
playerNotificationManager.setColorized(true);
playerNotificationManager.setUseChronometer(false);
playerNotificationManager.setSmallIcon(R.drawable.logo);
playerNotificationManager.setPlayer(player);
}
As said on the repo you need to extends the PlayerNotificationManager to do that you need to create this class and copy everything inside your project, and then add the layout you want to use as described in this link
You need to add your layout in the builder here
I'm learning Notifications, I use Android Studio 4.0 with latest androidx.core.app.NotificationManagerCompat.
There is a sample code about Notifications in the project user-interface-samples.
I find there are many differents about Notifications between this androidx and previous API.
Must the Notifications style be the one of BigTextStyleNotification, BigPictureStyleNotification, InboxStyleNotification and MessagingStyleNotification ?
Following are the notification styles available :
Notification.BigPictureStyle, Notification.BigTextStyle,
Notification.DecoratedCustomViewStyle, Notification.InboxStyle,
Notification.MediaStyle, Notification.MessagingStyle
You can get more info on this link.
Just for information purposes, to create a notification without hustle and get all predefined formatting in one place, just do the following :
Go to the Project Tab of android studio and right click.
Click on New -> UI Component -> Notification
Enter the required notification name
To call this notification just enter the following :
<NotificationClassName>.createNotification(getApplicationContext());
I want my FCM notifications to include a custom image and a vibration pattern.
The AndroidNotification class that Firebase provides as an example has both of these variables, but I haven't seen any way to get it working.
I've tried adding both of these variables to my notification message through a c# class AndroidNotification which gets serialized to json.
This is the documentation that makes me think it should be possible
https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages
I have watched multiple online videos and went through multiple forms, but have still been unable to set a custom vibration pattern or display image along with my app icon.
Lots of places suggest that I use a data only message so I can handle displaying the notification myself, but if that is the only way to do it way does the AndroidNotification documentation(linked above) show fields for both vibrate_timings and image?
Note :
I've been testing on Android Versions 4, 5, and 8. On 8 I set up a notification channel and everything works fine with that including the vibrations, but still no image.
The image is included locally in the my apk at the same path as my custom icon.
Also my apk is built with unity but I don't think that should effect things.
Here is the json payload I'm sending, I get my custom sound, custom icon, custom color etc just fine, it's only the image and vibrate_timings that don't seem to be working.
{
"validate_only":false,
"message":{
"data":null,
"android":{
"collapse_key":"new_messages",
"priority":1,
"restricted_package_name":"",
"data":{
},
"notification":{
"title":"A spoon is ready!",
"body":"Grab it before someone else!",
"icon":"spoonsbuzz",
"channel_id":"cow",
"color":"#0000FF",
"sound":"cow.wav",
"vibrate_timings":[
"0.0s",
"0.2s",
"0.1s",
"0.2s",
"0.1s",
"1.5s"
],
"visibility":2,
"tag":"new_messages",
"click_action":"",
"body_loc_key":"",
"body_loc_args":[
],
"title_loc_key":"",
"title_loc_args":[
],
"image":"spoonsbuzzimage",
"notification_priority":4
}
},
"apns":null,
"token":"Bot"
}
}
I expected my devices to get a notification with the image I added to the payload as well as vibrate in the pattern I set using vibrate_timings. The notification does come in just fine and everything else works but neither the image or the custom vibrations are included.
It's been a long time, but if someone has this problem they should add the default_vibrate_timings field, like this:
{...
default_vibrate_timings: false,
vibrate_timings: [
"0.0s",
"0.2s",
"0.1s",
"o.2s"
],
...}
For reference: Documenation Link
I would like to set the italic "Contents hidden" message for a public notification manually.
Android seem to set "Contents hidden" automatically if only a VISIBILITY_PRIVATE notification without a public counterpart is presented.
Here, the setContent-parts are automatically replaced.
For an example from K9mail see screenshot 1.
However, I would like to use a custom layout for the public notification while letting the notification look similar (i.e., "Contents hidden").
It is a notification for a music player, which should provide buttons for pause and play next songs.
So, how can I either
access the (localized) value for "Contents hidden" that Android is actually using (not implementing it manually) or
tell Android to replace all "setContent"-parts automatically as if I would not provide a public notification.
Any suggestions?
For the sake of completeness - the issue is related with this pull request: https://github.com/gateship-one/odyssey/pull/120
Pretty simple just use:
String foo = mContext.getString(android.content.res.Resources.getSystem().getIdentifier("notification_hidden_text", "string", "android"));
Im suffering from a problem in notification. Im doing my project in PHONEGAP.
I want to show multiple lines in push notification in android. Now i am only getting single line notification. i cannot expand or do anything with that notification. im using a phonegap plugin.
com.phonegap.plugins.PushPlugin
Please help me to overcome this problem.
Screen shot is given below.
Current Notification
Expected Notification
This involves a custom layout in the native notification (remoteviews) , so it is needed to modify you favorite plugin
Android custom notification layout with RemoteViews
In case of this plugin: https://github.com/phonegap-build/PushPlugin
Modify GCMIntentService.java, particulary NotificationCompat.Builder setContent with a the custom View. This custom view can be loaded from xml or instatiated by code: How to create a RelativeLayout programmatically with two buttons one on top of the other?
Example of a custom builder: Create custom notification, android
Change the params for the plugin or parse payload message to separate lines
Path: \platforms\android\src\com\plugin\gcm
Filename: GCMIntentService.java
String message = extras.getString("message");
if (message != null) {
mBuilder.setContentText(message);
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));//add this line