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
Related
I have an app with media buttons and text in the notification that I want to update programatically. So I did this:
public void updateNotificatonIcons() {
ArrayList<NotificationCompat.Action> acts = NotificationBuilder.mActions;
acts.set(1, new NotificationCompat.Action((isPlaying) ? R.drawable.my_media_stop : R.drawable.my_media_play, "Stop", stopintent));
NotificationBuilder.mActions = acts;
NotificationManagerCompat.from(context).notify(1, NotificationBuilder.build());
}
The problem is that AndroidStudio complains about NotificationBuilder.mActions:
Builder.mActions can only be accessed from within the same library group prefix (referenced groupId=androidx.core with prefix androidx from groupId=Android)
I googled and added a #SuppressLint("RestrictedApi") before the method, and it works.
Is this the "correct" way of updating the notification? Is there a better way without the need of a #SupressLint?
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 have created a new Ionic app and setup the cordova local notifications plugin to have notifications run in the background without the need for an external server such as Google Cloud Messaging using this plugin.
https://github.com/katzer/cordova-plugin-local-notifications
Everything seems to work but for some reason the icon shown in the notification isn't the one that I am setting in the js below - can anyone suggest what is wrong - it does show an icon, (an alarm bell) but it isn't the one that have I specified.
// within my $ionicPlatform.ready
$scope.scheduleSingleNotification = function () {
$cordovaLocalNotification.schedule({
id: 1,
title: 'Warning',
text: 'My first local notification this will stick!',
icon: '../img/github-icon.png'
}).then(function (result) {
console.log('Notification #1 triggered');
});
};
I had same problem few months back but than i have given a hit and trial an it worked for
create the icons of all sizes and copy them to /platforms/android/res/
and respective folders of sizes i hope that will solve problem
An always give the path of img respect to your index file not the file in which your are coding but to the main file in which it's included
Make sure that the icon has a white or transparent background. If you take a look at the documentation:
Android notifications
icons should only be a white-on-transparent background image.
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?.